So, I'm implementing a Discord Bot using discord.py, and I'm trying to dynamically call functions based on commands. I was able to test dynamic function calls with exec() fine, but they seem to fall apart with the async calls needed for discord.py.
So what I'm trying to do with this example would be to call the hello function and print Hello World into discord by typing !hello in chat.
@client.event
async def on_message(message):
call = 'await ' + message.content.lower()[1:] + '(message)'
exec(call)
async def hello(message):
await client.send_message(message.channel, 'Hello World')
Unfortunately, this code doesn't seem to do anything, I'm assuming because of how exec() handles async calls. Any help would be appreciated.