简体   繁体   中英

Discord Bot Responding to Phrase (Discord.py Rewrite)

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.

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()

on_message 只有 message 参数,所以在没有 ctx 的情况下尝试它。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM