I have an extremely basic script that pops up a message with a button with the command ?place
Upon clicking this button the bot replies Hi to the user who clicked it.
If the button isn't interacted with for > approx 3 minutes it then starts to return "interaction failed".
after that the button becomes useless. I assume there is some sort of internal timeout i can't find in the docs. The button does the same thing whether using discord.py (2.0) or pycord. Nothing hits the console. It's as if the button click isn't picked up.
Very occasionally the button starts to work again and a host of these errors hit the console:
discord.errors.NotFound: 404 Not Found (error code: 10062): Unknown interaction
Ignoring exception in view <View timeout=180.0 children=1> for item <Button style=<ButtonStyle.success: 3> url=None disabled=False label='click me' emoji=None row=None>:
I assume the timeout = 180 is the cause of this issue but is anyone aware of how to stop this timeout and why it's happening? I can't see anything in the docs about discord buttons only being usable for 3 mins.
import discord
from discord.ext import commands
intents = discord.Intents.default()
intents.members = True
intents.message_content = True
bot = commands.Bot(command_prefix="?", intents=intents)
embed1=discord.Embed(title="Test", description = f"TESTING",color=0xffffff)
print("bot connected")
@ bot.command(name='place')
async def hello(ctx):
view = discord.ui.View()
buttonSign = discord.ui.Button(label = "click me", style= discord.ButtonStyle.green)
async def buttonSign_callback(interaction):
userName = interaction.user.id
embedText = f"test test test"
embed=discord.Embed(title="Test", description = embedText,color=0xffffff)
await interaction.response.send_message(f"Hi <@{userName}>")
buttonSign.callback = buttonSign_callback
view.add_item(item=buttonSign)
await ctx.send(embed = embed1,view = view)
bot.run(TOKEN)
CodePudding user response:
Explanation
By default, View
s in discord.py 2.0 have a timeout of 180 seconds (3 minutes). You can fix this error by passing in None
as the timeout when creating the view.
Code
@bot.command(name='place')
async def hello(ctx):
view = discord.ui.View(timeout=None)