b00walk3r
b00walk3r

Reputation: 11

discord.py not detecting messages, i want it to detect specific word in messages but it doesnt work

discord.py not detecting messages

@client.event
async def on_messge(ctx):
    msg = ctx.content()
    words_list = ["check", 'for', 'any', 'word', 'from', 'list']

    if any(word in msg for word in words_list):
      await ctx.send("message here")

discord.py not detecting messages, i want it to detect specific word in messages but it doesnt work

my bot needs to detect the specific word in the message but it doesnt

where am i making the mistake?

Upvotes: 0

Views: 68

Answers (1)

stijndcl
stijndcl

Reputation: 5650

First of all, the event is called on_message, not on_messge, so your event handler will never get called. However, there's a lot more issues than that.

on_messge(ctx)

As the docs page will also tell you, the argument passed to on_message is a discord.Message instance, not a Context instance, so using it as a Context will never work.

msg = ctx.content()

Context.content() doesn't exist, as the docs for Context will tell you, but luckily for you (as mentioned above) it's actually a Message and not a Context instance, so that won't be a problem in this case. However, content is an attribute, not a method, so you can't call it.

await ctx.send("message here")

Again, the argument is a Message instance, and Message.send() doesn't exist either as the docs for Message will tell you. Either use Message.reply(), or send a message to the channel instead.

All in all, make sure you read the docs for something before randomly using it and assuming it exists or that it will work.

Upvotes: 1

Related Questions