Is there a way to look for a role ping? (discord.py)

410 Views Asked by At

Title says it all. I tried looking for the id:

if "845314564555931660" in message.content:

I tried looking for the id in an integer:

if 845314564555931660 in message.content:

The integer recognizes it but gets an error because it's looking for an int in a str.

I tried converting the id into a ping:

if <@845314564555931660> in message.content:

I tried using the ping alone:

if "@Sugarcane" in message.content:

None can detect the message.

1

There are 1 best solutions below

0
On

You can use the discord.Message.role_mentions or discord.Message.raw_role_mentions attributes.

  • .role_mentions returns a list of discord.Role objects that were mentioned in the message
  • .raw_role_mentions returns a list of role IDs as integers.