I have a very simple discord bot running in python 3.6.9.
Any time I call either of the 2 commands (ping or whenmonster), the first call takes upwards of 30 seconds to respond to discord with its message. On subsequent calls, it takes considerably less time, less than a second.
If I wait 30 seconds without calling any commands, the bot is once again slow, even after previously responding just fine.
- Nothing shows in the log, no sort of gateway reset, no errors handled.
- I kicked the bot out of the server and re-invited, and the behavior persists.
- I don't think I'm accidentally spamming the server, so the bot shouldn't be hitting the built-in discord timeout.
- We have other bots in the server that don't exhibit this behavior.
- When I run the ping command, latency always comes back to just 0.1 seconds.
- I tried just printing the websocket object to see if the bot was making a new one, seems to always be the same one
Is this a discord API thing? I just don't get what's going on to cause this. I'm literally crying thinking about all the funny things my friends are missing out on not using my bot. I just want them to know whenever they want, without delay, how many days there are until Godzilla just whoops King King back to monke island. Preciate any help!
import discord
from discord.ext import commands
import datetime
intents = discord.Intents.default()
intents.members = True
token = my_token
class MyBot(commands.Bot):
async def on_ready(self):
print('Logged in!')
print('Username: {0.name}\nID: {0.id}'.format(self.user))
bot = MyBot(command_prefix='$', intents=intents)
@bot.command()
async def ping(ctx):
await ctx.send('Pong! {}'.format(round(bot.latency, 1)))
@bot.command()
async def whenmonster(ctx):
monster_time = datetime.datetime(2021, 3, 31)
now = datetime.datetime.now()
delta = monster_time - now
days = delta.days
seconds = delta.seconds % 60
minutes = (delta.seconds // 60) % 60
hours = (delta.seconds //3600)
msg = 'Time remaining until Kong gets his ass whooped: {} days, {} hours, {} minutes, {} seconds'.\
format(days, hours, minutes, seconds)
await ctx.send(msg)
bot.run(token)
monster_time = datetime.datetime(2021, 3, 31)
now = datetime.datetime.now()
tomonster_time = datetime(2021, 3, 31)
now = datetime.now()
which I don't think it makes any difference. So I don't think your issue has to do with the code itself. – Cristian Feb 28 at 2:32