Функция exec() не работает disnake

Рейтинг: 0Ответов: 0Опубликовано: 28.03.2023
@bot.command()
async def calc(ctx, *arg):
  a = ''
  for i in arg:
    a = a + i
  exec('a = ' + a)
  await ctx.reply(a)

В *arg должна поступать информация по типу 1+1 9-7 и т.д. но в итоге выходит ошибка:

Traceback (most recent call last):
  File "/home/runner/PYDEN/venv/lib/python3.10/site-packages/disnake/ext/commands/core.py", line 173, in wrapped
    ret = await coro(*args, **kwargs)
  File "main.py", line 180, in calc
    await ctx.reply(exec('a =', a))
TypeError: exec() globals must be a dict, not str

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

Traceback (most recent call last):
  File "/home/runner/PYDEN/venv/lib/python3.10/site-packages/disnake/ext/commands/bot_base.py", line 589, in invoke
    await ctx.command.invoke(ctx)
  File "/home/runner/PYDEN/venv/lib/python3.10/site-packages/disnake/ext/commands/core.py", line 914, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "/home/runner/PYDEN/venv/lib/python3.10/site-packages/disnake/ext/commands/core.py", line 182, in wrapped
    raise CommandInvokeError(exc) from exc
disnake.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: exec() globals must be a dict, not str```

Ответы

Ответов пока нет.