'Discord py components, interaction failed issue
So, I am having a issue with my button interactions. The first button named "Music" correctly triggers the button_click interaction and works perfectly. However, when I added a interaction for the second button on the embed named "Admin", it does not trigger when clicked. It gives the error "Interaction failed" but it's setup the same as the first button interaction "Music". I don't know what I am doing wrong and can't seem to find a solution.
My current code
## discord_components
@client.command() # HELP MENU BUTTON
async def help(ctx):
embed = discord.Embed(title="**:sos: Help Menu:**", colour= orange)
embed.add_field(name="Choose the category you would like help with!", value=":mag:", inline=False)
await ctx.send(embed=embed, components = [
[Button(label="Music", style="4", emoji = "🎶", custom_id="music"), Button(label="Admin", style="4", emoji = "🔧", custom_id="admin")]
])
interaction = await client.wait_for("button_click", check = lambda i: i.custom_id == "music") # MUSIC HELP INTERACTION
await ctx.channel.purge(limit=1)
embed = discord.Embed(title=":scroll: Music Help", colour= yellow)
embed.add_field(name="!play", value="Adds a song to the queue either by YouTube URL or YouTube Search.", inline=False)
embed.add_field(name="!stop", value="Admin command that stops playback of music and clears out the music queue.", inline=False)
embed.add_field(name="!skip", value="Puts in your vote to skip the currently played song.", inline=False)
embed.add_field(name="!fskip", value="Admin command that forces skipping of the currently playing song.", inline=False)
embed.add_field(name="!songinfo", value="Print out more information on the song currently playing.", inline=False)
embed.add_field(name="!remove", value="Removes the last song you requested from the queue, or a specific song if queue position specified.", inline=False)
embed.add_field(name="!fremove", value="Admin command to forcibly remove a song from the queue by it's position.", inline=False)
embed.add_field(name="!queue", value="Prints out a specified page of the music queue, defaults to first page.", inline=False)
await interaction.send(embed=embed)
interaction2 = await client.wait_for("button_click", check = lambda i: i.custom_id == "admin") # MODERATION HELP INTERACTION
if ctx.author.guild_permissions.administrator:
await ctx.channel.purge(limit=1)
embed = discord.Embed(title=":scroll: Moderation Help", colour= yellow)
embed.add_field(name="!announce", value="Makes an announcement in whatever channel you run it in. Your message must be in quotes", inline=False)
embed.add_field(name="!messageall", value='Sends a message to all users. Your message must be in quotes "ex." ', inline=False)
await interaction2.send(embed=embed)
else:
embed = discord.Embed(title=":Error:", colour= yellow)
embed.add_field(name=':warning:', value="You do not have administrative permissions.", inline=False)
await interaction2.send(embed=embed)
Note: I have DiscordComponents(client) in my code.
Solution 1:[1]
After playing with this for sometime, I changed my code around and finally got it to work.
Updated & working code:
@client.command() # HELP MENU BUTTON
async def help(ctx):
embed = discord.Embed(title="**:sos: Help Menu:**", colour= orange)
embed.add_field(name="Choose the category you would like help with!", value=":mag:", inline=False)
await ctx.send(embed=embed, components = [
[Button(label="Music", style="4", emoji = "?", custom_id="music"), Button(label="Admin", style="4", emoji = "?", custom_id="admin")]
])
interaction = await client.wait_for("button_click") # MUSIC HELP INTERACTION
if interaction.component.label == "Music":
await ctx.channel.purge(limit=1)
embed = discord.Embed(title=":scroll: Music Help", colour= yellow)
embed.add_field(name="!play", value="Adds a song to the queue either by YouTube URL or YouTube Search.", inline=False)
embed.add_field(name="!stop", value="Admin command that stops playback of music and clears out the music queue.", inline=False)
embed.add_field(name="!skip", value="Puts in your vote to skip the currently played song.", inline=False)
embed.add_field(name="!fskip", value="Admin command that forces skipping of the currently playing song.", inline=False)
embed.add_field(name="!songinfo", value="Print out more information on the song currently playing.", inline=False)
embed.add_field(name="!remove", value="Removes the last song you requested from the queue, or a specific song if queue position specified.", inline=False)
embed.add_field(name="!fremove", value="Admin command to forcibly remove a song from the queue by it's position.", inline=False)
embed.add_field(name="!queue", value="Prints out a specified page of the music queue, defaults to first page.", inline=False)
await interaction.send(embed=embed)
if interaction.component.label == "Admin":
if ctx.author.guild_permissions.administrator:
await ctx.channel.purge(limit=1)
embed = discord.Embed(title=":scroll: Moderation Help", colour= yellow)
embed.add_field(name="!announce", value="Makes an announcement in whatever channel you run it in. Your message must be in quotes", inline=False)
embed.add_field(name="!messageall", value='Sends a message to all users. Your message must be in quotes "ex." ', inline=False)
await interaction.send(embed=embed)
else:
embed = discord.Embed(title=":Error:", colour= yellow)
embed.add_field(name=':warning:', value="You do not have administrative permissions.", inline=False)
await interaction.send(embed=embed)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | CRM000 |


