N
N
Nekit Strelok2021-09-10 17:54:00
Python
Nekit Strelok, 2021-09-10 17:54:00

How to make according to the correct discord.py?

I have such code

@bot.command(pass_context=True)
async def exec(ctx, *, text: str):
    exec(text)
    await ctx.send("Code succesfully executed")

But when I write for example *exec await bot.get_channel(go to your channel).send('123')
Then it writes errors
C:\Users\Admin\Desktop\bot\testbot.py:33: RuntimeWarning: coroutine 'Command. __call__' was never awaited
exec(text)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Prokopenko, 2021-09-10
@Goverl

Of course, I don’t understand this, but why are you calling the exec function in the exec function itself? As far as I know, in the current version of discord.py, you can not write pass_context=True

M
Maxim Nevzorov, 2021-09-11
@fixator10

Don't use built-in function names for your own functions.
Your team is trying to execute itself.
And I really hope that you are executing this code on a machine that is not a pity. Because giving access to code execution to any Internet user is a bad idea.

@bot.command(name="exec")
@commands.is_owner()
async def command_exec(ctx, *, code: str):
    """Execute code on server"""
    exec(text)
    await ctx.send("Done")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question