Discord 机器人始终需要很长时间才能发送消息

问题描述 投票:0回答:1

我有一个非常简单的不和谐机器人,在 python 3.6.9 中运行。

每当我调用这 2 个命令(ping 或whenmonster)中的任何一个时,第一个调用都会花费 30 秒以上的时间来响应与其消息不一致的情况。在后续调用中,所需时间要少得多,不到一秒。

如果我等待 30 秒而不调用任何命令,机器人会再次变慢,即使之前响应得很好。

  • 日志中没有显示任何内容,没有网关重置,没有错误 已处理。
  • 我将机器人踢出服务器并重新邀请,其行为 持续存在。
  • 我不认为我无意中向服务器发送了垃圾邮件,所以机器人 不应该遇到内置的不和谐超时。
  • 我们的服务器中还有其他机器人没有表现出这种行为。
  • 当我运行 ping 命令时,延迟总是回到 0.1 秒。
  • 我尝试打印 websocket 对象来查看机器人是否正在创建一个新的对象,似乎总是相同的

这是一个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)
python discord discord.py
1个回答
0
投票

原来我的路由器上的 DNS 设置是默认 ISP,切换到 google 作为主要和备份使解析更加快捷。

© www.soinside.com 2019 - 2024. All rights reserved.