簡體   English   中英

如何檢查消息作者的角色 + 如何在 Discord.py 上 DM 特定角色?

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

所以我正在制作一個 Discord 機器人,當有人違反規則時,它會扮演 DM 角色。 這是我的第一個 discord 機器人,並且真的剛剛開始使用 GitHub 上的示例。 我似乎找不到如何檢查角色或 DM 每個角色。 我發現了類似的東西

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

還有檢查角色的東西。 雖然它總是說“成員沒有屬性'server_privileges”或類似的東西。 無論如何,我希望你們能幫助我。 這些是我需要完成的最后一件事。 這是我的代碼:

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 是我制作的 class,其中包含檢查是否有人違反規則的功能。 你推薦的任何東西都會很棒,而且很有幫助。

您可以使用 Guild.get_role 獲得discord.Role實例,並將其與in關鍵字與Guild.get_role進行Member.roles

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

參考:

看起來我找到了如何使用 discord.py 與人交流。 您只需使用 API 文檔中的發送 function即可。 希望這可以幫助其他需要這個的人:D

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM