我想让机器人写出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'有人能帮帮我吗?
发布于 2021-08-06 13:19:28
{}语法实例化set。在为ping赋值时删除它们
ping = {round(bot.latency * 1000)} ping = round(bot.latency * 1000)https://stackoverflow.com/questions/68682241
复制相似问题