简体   繁体   中英

How can I check the role of a message author + How do I DM specific roles on Discord.py?

So I am making a Discord bot that DMs mod-type roles when someone goes against the rules. This is my first discord bot, and have really just been going off the example on GitHub. I can't seem to find how to check a role or DM everyone in a role. I found stuff like

if message.author.server_privileges("kick_members"):

And stuff for checking the role. Although it always says "member has no attribute 'server_privileges" or something like that. Anyways, I was hoping you guys could help me. These are the last things I need to finish. Here's my code:

class MyClient(discord.Client):
   async def on_ready(self):
       print("")
       print('Logged on as', self.user)

   async def on_message(self, message):
       reasons = []

       # don't respond to ourselves
       if message.author == self.user:
           return

       if CheckBot.susCheck(self, message.content, susWords):
           reasons.append("Being sus")
           # DM staff, admins, and headstaff
           report = "Caught " + str(message.author) + " being sus with the following message: \n" + message.content
           print("")
           print("####################-END-####################")
           print("")
           print(report)

       if CheckBot.badCheck(self, message.content, badWords):
           reasons.append("Saying bad words")
           # DM staff, admins and headstaff
           report = "Caught " + str(message.author) + " saying bad words with the following message: \n" + message.content
           print("")
           print("####################-END-####################")
           print("")
           print(report)

       if #Check if message author has certain role:
           if CheckBot.spamCheck(self, message.content, 100000000000000000):
               reasons.append("Spam")
               # DM staff, admins, and headstaff
               report = "Caught " + str(message.author) + " spamming with the following message: \n" + message.content
               print("")
               print("####################-END-####################")
               print("")
               print(report)
       else:
           if CheckBot.spamCheck(self, message.content, 55):
               reasons.append("Spam")
               # DM staff, admins, owner, and headstaff
               report = "Caught " + str(message.author) + "spamming with the following message: \n" + message.content
               print("")
               print("####################-END-####################")
               print("")
               print(report)

CheckBot is a class I made, that contains the functions that check if someone is going against the rules. Anything you recommend would be great, and helpful.

You can get a discord.Role instance with Guild.get_role and compare it with the in keyword with Member.roles

role = message.guild.get_role(ROLE_ID_HERE)
if role in message.author.roles:
    # Has the role, do something here

Reference:

Looks like I found how to DM people with discord.py. You just use the send function from the API docs. Hope this helps anybody else that needed this:D

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