[英]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.所以我正在制作一个 Discord 机器人,当有人违反规则时,它会扮演 DM 角色。 This is my first discord bot, and have really just been going off the example on GitHub.
这是我的第一个 discord 机器人,并且真的刚刚开始使用 GitHub 上的示例。 I can't seem to find how to check a role or DM everyone in a role.
我似乎找不到如何检查角色或 DM 每个角色。 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.
虽然它总是说“成员没有属性'server_privileges”或类似的东西。 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. CheckBot 是我制作的 class,其中包含检查是否有人违反规则的功能。 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
您可以使用 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
Looks like I found how to DM people with discord.py.看起来我找到了如何使用 discord.py 与人交流。 You just use the send function from the API docs.
您只需使用 API 文档中的发送 function即可。 Hope this helps anybody else that needed this:D
希望这可以帮助其他需要这个的人:D
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.