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):
- User1 types .test
- User2 types .test
- User1 presses their 1 button.
- User2 presses their 1 button.
- 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.
If Else is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.