When two discord users interact with two different buttons, why does the later view created replace the earlier view?

I believe this is the minimal reproducible code.

from discord.ui import View,Button

from discord.ext import commands

import discord

import asyncio

client = commands.Bot(command_prefix = ‘.’, intents=discord.Intents.all(), case_insensitive=True)
@client.command()

async def test(ctx):
testclass = TestCog(ctx)
await testclass.test()

class TestCog():

def __init__(self, ctx):
    self.ctx = ctx

async def test(self):

    view = TestView(self.ctx)
    message = await self.ctx.send(view=view)
    view.message = message

class TestView(View):
def init(self, ctx):
super().init(timeout=None)
self.interaction_received = False
self.ctx = ctx
self.message = None

@discord.ui.button(label="1", style=discord.ButtonStyle.success, custom_id= 'one')
async def yes_button(self, interaction:discord.Interaction, button: Button):

    if interaction.user.id != self.ctx.author.id:
        await self.ctx.send(f"interaction id:{interaction.user.id} and uid:{self.ctx.author.id}")
        await self.ctx.send(f"{self.message.interaction_metadata}")
        return
    
    view = TestView2(self.ctx)
    ### POSSIBLE AREA OF INTEREST
    await interaction.response.send_message(view=view)
    ###################################################
    message = await interaction.original_response()
    view.message = message
    self.disable_buttons()
    await self.message.edit(view=self)

def disable_buttons(self):
    for item in self.children:
        item.disabled = True

class TestView2(View):
def init(self,ctx):
super().init(timeout=None)
self.interaction_received = False
self.ctx = ctx
self.message = None

@discord.ui.button(label="2", style=discord.ButtonStyle.success, custom_id= 'two')
async def yes_button(self, interaction:discord.Interaction, button: Button):
    if interaction.user.id != self.ctx.author.id:
        await self.ctx.send(f"interaction id:{interaction.user.id} and uid:{self.ctx.author.id}")
        await self.ctx.send(f"{self.message.interaction_metadata}")
        return

    view = TestView(self.ctx)
    await interaction.response.send_message(view=view)
    message = await interaction.original_response()
    view.message = message
    self.disable_buttons()
    await self.message.edit(view=self)

def disable_buttons(self):
    for item in self.children:
        item.disabled = True

async def main():
await client.start(BOTTOKEN)

asyncio.run(main())

Steps to reproduce bug (requires two users):

  1. User1 types .test
  2. User2 types .test
  3. User1 presses their 1 button.
  4. User2 presses their 1 button.
  5. User1 can try to press their 2 button, but will find out they can’t.

So I tried the “Steps to reproduce bug” above and I expected User1 is able to press their 2 button even after User2 presses their 1 button. What actually happened was that User1 was unable to press their 2 button.

NOTE: I know there is this snippet of code that makes sure the author is the same user interacting with the button.
if interaction.user.id != self.ctx.author.id:
await self.ctx.send(f”interaction id:{interaction.user.id} and uid:{self.ctx.author.id}”)
await self.ctx.send(f”{self.message.interaction_metadata}”)
return

I know this stops the interaction, but the problem is either self.ctx.author.id is getting replaced, the interaction response object is the same so the second press of the 1 button is replacing the view of the first press of the 1 button, OR something else is going on.

New contributor

If Else is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật