I’m working on a Discord bot using discord.py and running into an issue where button interactions are failing. When users click my buttons, they see an interaction failed message but no errors show up in my console.
Here’s my current code:
class WelcomeView(discord.ui.View):
@discord.ui.button(label="Accept", style=discord.ButtonStyle.green)
async def accept_user(self, interaction: discord.Interaction, button: discord.ui.Button):
await interaction.response.send_message(content="User accepted!", ephemeral=True)
@discord.ui.button(label="Reject", style=discord.ButtonStyle.danger)
async def reject_user(self, interaction: discord.Interaction, button: discord.ui.Button):
await interaction.response.send_message(content="User rejected!")
@client.event
async def on_member_join(new_member: discord.Member):
welcome_view = WelcomeView()
target_role = discord.utils.get(new_member.guild.roles, name="NewMember")
admin_channel_id = 1158716789103013898
admin_channel = new_member.guild.get_channel(admin_channel_id)
if admin_channel is not None:
await new_member.add_roles(target_role)
await admin_channel.send(f"{new_member} has joined! Please review:", view=welcome_view)
await welcome_view.wait()
else:
print(f"Could not find channel with ID {admin_channel_id}")
The bot should automatically assign a role when someone joins and send a message to an admin channel with accept/reject buttons. The buttons appear correctly but clicking them causes the interaction to fail. Any ideas what might be causing this?