Someone
Someone

Reputation: 84

Check ping command

I wanted the bot to write what ping is, for example great, but I have an error all the time. This is my code:

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)

And this is an error:

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'

Can anyone help me, please?

Upvotes: 0

Views: 105

Answers (1)

edd
edd

Reputation: 1417

The {} syntax instantiates a set. Remove them when assigning a value to ping

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

Upvotes: 3

Related Questions