#Discord Bot stops working after nearly 5 hours

1 messages · Page 1 of 1 (latest)

mint trail
#

Discords says the bot is online but isnt reactiong to commands or anything the command line says that the bot got online more then once the time and isn't showing any errors

dim pulsar
#

What hosting are you using?

foggy totem
mint trail
#

Selfhosted on root server

dim pulsar
#

Not Termux?

#

Pycord v2 or v3?

mint trail
mint trail
foggy totem
#

Are they slash commands

mint trail
dim pulsar
#

Do you have tasks or not async commands?

mint trail
foggy totem
#

What's your code

#

How are you initializing your bot class

mint trail
foggy totem
#

And what's the code for your slash command

mint trail
foggy totem
#

The whole slash command code

#

The decorator tells me nothing

mint trail
#

`@bot.slash_command(guild_ids=[guildid],name="verwarnen",description="""Verwarnt einen User""")
@commands.has_permissions(kick_members = True)
async def verwarnen(ctx, member: Option(discord.Member, description= "Wen möchtest du verwarnen?",ephemeral=True), reason: Option(str, description= "Grund",ephemeral=True, required = True)):
mycursor = mydb.cursor()
id = member.id
sql = 'INSERT INTO warnings (name, id, time, reason) VALUES ("' + str(member.name) + '", "' + str(id) + '", "' + str(int(time.time())) + '"' + ', "' + str(reason) + '")'
mycursor.execute(sql)
mydb.commit()

sql = "SELECT reason FROM warnings WHERE EXISTS (SELECT id FROM warnings WHERE id = " + str(member.id) + ")"
mycursor.execute(sql)
myresult = mycursor.fetchall()
counter = 0
for item in myresult:
#Incrementing counter variable to get each item in the list
    counter = counter + 1
view = KickView(member, reason)
#await ctx.send(f"Are you sure you want to kick {member.name}?", view=view)
await ctx.respond("der " + str(counter) + ". Verstoß", view=view, ephemeral=True)
embed=discord.Embed(title="Verwarnung", description=member.mention + "\nHiermit wirst du aus folgendem Grund zum  " + str(counter) + ". mal verwarnt: \n" + reason, color=0xff0000)
if counter == 1:
    embed.set_footer(text="Bitte halte dich an unsere Serverregeln und pflege einen respektvollen und gewaltfreien Umgang mit den anderen Usern.")
elif counter == 2:
    embed.set_footer(text="Noch so´n Ding, Augenring!")
elif counter >= 3 :
    embed.set_footer(text="Noch so´n Spruch, Kieferbruch!")
await member.send(embed=embed)`
#

there are more shlash commands but buttons and other stuff isnt working either and after a restart everything is working again

foggy totem
#
  1. You're taking too long to send a response
  2. You are not sending a response
#

use await ctx.defer() at the start of your callback

#

And then use ctx.respond to respond, not ctx.send

mint trail
#

and with buttons and so the same?

foggy totem
#

Deferring depends on how long you'll take to respond

#

You don't defer just because

#

If you think and assume you'll take more than 3 seconds to respond, then you defer

mint trail
#

ok but why is it so that when the bot starts everything is working but after hours it 'stops'?

foggy totem
#

The only different thing with buttons (or views generally), is that you use interaction.response.defer() and respond with interaction.folloup.send() instead

mint trail
#

And thank you for the quick response 😀

foggy totem
#

I assume that's a problem with your hosting

mint trail
foggy totem
#

You need to also tell the defer function you'll respond ephemeral too

mint trail
#

so defer(ephemeral=True) ???

foggy totem
#

Indeed