I’m having trouble with my Discord bot running on a friend’s Raspberry Pi VPS. It starts fine and responds to commands for about 5 minutes, but then it stops working properly. When I click the green button, I get an “Interaction Failed” message. If I try the command again, it works and remembers the user ID in the sign-in dictionary. But after another 5 minutes, the same issue happens.
The bot doesn’t seem to completely stop, but something’s not right. Could this be a code issue or a VPS problem? Here’s a simplified version of my code:
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix='!')
user_data = {}
@bot.command()
async def register(ctx):
button = discord.ui.Button(label='Sign Up', style=discord.ButtonStyle.green)
async def button_click(interaction):
if interaction.user.id in user_data:
await interaction.response.send_message('Already registered', ephemeral=True)
return
await interaction.response.send_modal(RegistrationForm())
button.callback = button_click
view = discord.ui.View()
view.add_item(button)
await ctx.send('Click to register', view=view)
class RegistrationForm(discord.ui.Modal):
def __init__(self):
super().__init__(title='Registration Form')
self.username = discord.ui.TextInput(label='Username')
self.add_item(self.username)
async def on_submit(self, interaction):
user_data[interaction.user.id] = {'username': self.username.value}
await interaction.response.send_message('Registration complete!', ephemeral=True)
bot.run('YOUR_TOKEN_HERE')
Any ideas on what might be causing this intermittent behavior?