A
A
ArtyomKor2021-11-24 13:58:22
Python
ArtyomKor, 2021-11-24 13:58:22

Discord.py bot code not working, what should I do?

Hello, this piece of code is not working:

@bot.command()
async def status(self, ctx: discord.ext.commands.Context):
    uptime_timedelta: datetime.timedelta = datetime.datetime.today() - self.start_time
    uptime = str(uptime_timedelta).split(".")[0]
    server_uptime = datetime.datetime.fromtimestamp(psutil.boot_time())
    embed = discord.Embed(title=f"Статус ABot",
                          colour=discord.Color.purple())
    embed.add_field(name="Версия Python", value=sys.version[:3])
    embed.add_field(name="Версия discord.py", value=discord.__version__)
    embed.add_field(name="Uptime", value=uptime)
    embed.add_field(name="Информация о сервере", value=f"Загрузка ЦП: `{psutil.cpu_percent(interval=None)}%`\n"
                                                       f"RAM: `{psutil.virtual_memory().used//1024//1024} МБ`/`{psutil.virtual_memory().total//1024//1024} МБ`\n"
                                                       f"Uptime: `{str(datetime.datetime.today() - server_uptime).split('.')[0]}`")
    await ctx.send(embed=embed)


In response I get an error:
Ignoring exception in command status:
Traceback (most recent call last):
  File "C:\Users\kps4\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Users\kps4\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\core.py", line 855, in invoke
    await self.prepare(ctx)
  File "C:\Users\kps4\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\core.py", line 789, in prepare
    await self._parse_arguments(ctx)
  File "C:\Users\kps4\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\core.py", line 697, in _parse_arguments
    transformed = await self.transform(ctx, param)
  File "C:\Users\kps4\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\core.py", line 542, in transform
    raise MissingRequiredArgument(param)
discord.ext.commands.errors.MissingRequiredArgument: ctx is a required argument that is missing.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
retUrn3d, 2021-11-24
@ArtyomKor

ctxMust be passed as the first argument.

T
Telmor, 2021-11-24
@Telmor

Why do you write ctx: discord.ext.commands.Context
when you can just ctx??
This is most likely an error.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question