0
votes

Right now, I am trying to code an event for a Discord Bot (Using the Discord.py Rewrite package) that would send an image upon certain phrase being sent in the chat.

Based upon the error messages I been having, it looks like it is not passing the Message argument, as it is likely I am missing something somewhere. The Listener seems like it is working as it should be (It triggers the moment someone says something in chat).

Here is the error message I am receiving for reference:

Ignoring exception in message Traceback (most recent call last):

File "C:\Program Files (x86)\Python36-32\lib\site->packages\discord\client.py", line 221, in _run_event await coro(*args, **kwargs) TypeError: dealwithit() missing 1 required >positional argument: 'message'

Here is the code snippet for reference

@bot.event
async def dealwithit(ctx,message):
    msg = message.content
    msg = msg.lower()
    msg = "".join(msg.split())
    if ctx.user.id != message.author.id:
        if msg == "dealwithit":
            dealwithit= discord.File('swag.jpg', filename='swag.jpg')
            await client.send_message(content=None,file=dealwithit)

bot.add_listener(dealwithit,'on_message')

Any assistance on what I might be missing that is not passing the arguments over, or have set up incorrectly would be appreciated.

2
you might want to use bot.command instead of bot.eventjavajav
That does not work. Gives me an error: File "C:\Program Files (x86)\Python36-32\lib\site-packages\discord\ext\commands\bot.py", line 455, in add_listener raise discord.ClientException('Listeners must be coroutines') discord.errors.ClientException: Listeners must be coroutinesRyu Shishin
Listeners and events do not get passed the ctx. And you need to get rid of @bot.event as dealwithit isn’t an event name.abccd

2 Answers

1
votes

Here's a rewrite of that using discord commands

    bot = commands.Bot(command_prefix='!')
    @bot.command(pass_context=True)
    async def dealwithit(ctx):
        sendfile = open("swag.jpg", "rb")
        await bot.send_file(ctx.author.channel, sendfile)
        sendfile.close()
0
votes

on_message has only the message argument, so try it without ctx.