【问题标题】:Check ping command检查 ping 命令
【发布时间】:2021-08-06 21:19:28
【问题描述】:

我希望机器人写出 ping 是什么,例如很棒,但我一直有一个错误。这是我的代码:

def get_ping():
  ping = {round(bot.latency * 1000)}
  if ping > 100:
    return ("Good")
  elif ping < 100 and ping > 300:
    return ("OK")
  elif ping < 300:
    return ("Bad")

@bot.command()
async def ping(ctx):
  ping = get_ping()
  await ctx.send(ping)

这是一个错误:

Ignoring exception in command ping:
Traceback (most recent call last):
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "main.py", line 21, in ping
    ping = get_ping()
  File "main.py", line 12, in get_ping
    if ping > 100:
TypeError: '>' not supported between instances of 'set' and 'int'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 939, in invoke
    await ctx.command.invoke(ctx)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 863, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 94, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: '>' not supported between instances of 'set' and 'int'

有人可以帮帮我吗?

【问题讨论】:

    标签: python discord.py


    【解决方案1】:

    {} 语法实例化 set。为ping赋值时删除它们

      ping = {round(bot.latency * 1000)}
    
      ping = round(bot.latency * 1000)
    

    【讨论】:

    • 谢谢!它有帮助
    猜你喜欢
    • 1970-01-01
    • 2014-08-23
    • 2020-12-04
    • 2020-10-13
    • 1970-01-01
    • 2018-09-21
    • 2013-08-13
    • 2020-04-29
    • 2016-04-01
    相关资源
    最近更新 更多