我有一个非常简单的不和谐机器人,在 python 3.6.9 中运行。
每当我调用这 2 个命令(ping 或whenmonster)中的任何一个时,第一个调用都会花费 30 秒以上的时间来响应与其消息不一致的情况。在后续调用中,所需时间要少得多,不到一秒。
如果我等待 30 秒而不调用任何命令,机器人会再次变慢,即使之前响应得很好。
这是一个discord API 的事情吗?我只是不明白发生了什么导致这种情况。想到我的朋友们因不使用我的机器人而错过的所有有趣的事情,我真的哭了。我只是想让他们知道,无论何时,只要他们愿意,毫不拖延地,还有多少天,哥斯拉就会呼喊国王国王回到僧侣岛。感谢任何帮助!
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)
原来我的路由器上的 DNS 设置是默认 ISP,切换到 google 作为主要和备份使解析更加快捷。