Discord.py重写使机器人对DM做出响应

时间:2020-04-25 02:46:34

标签: discord.py discord.py-rewrite dm

我正在尝试让我的漫游器响应接受规则的DM消息。

这是我到目前为止所拥有的:

@bot.event
async def on_member_join(member):
  role = discord.utils.get(member.servers.roles, name='Newcomers') #get role
  await bot.add_roles(member, role) #give the role to the user
  await bot.member.send("Welcome to the Moderator Bot Server! I will need you to first read the rules then accept by using the `mbs accept` in this DM")#send a message
  #wait for accept

1 个答案:

答案 0 :(得分:0)

这是我的查询代码:

role = discord.utils.get(member.guild.roles, name='Newcomers') #get role
await member.add_roles(role) #give the role to the user
await member.send("Welcome to the Moderator Bot Server! I will need you to first read the rules then accept by using the `mbs accept` in this DM")#send a message

def check(m):
    return isinstance(m.channel, discord.DMChannel) and m.author == member and m.content == "mbs accept"

await bot.wait_for("message", check=check)
#do stuff here; this line runs once the user types `mbs accept` in the DM (maybe you want to send the user a message that thanks them for accepting the rules?)

前 3 行是您提供给我们的,尽管我更新了它们,以便它们适用于 discord.py-rewrite(在 discord.py rewrite 文档 here 上阅读更多内容。

检查功能

然后,check 函数首先检查发送消息的频道是否为 DM,检查作者是否为成员,并检查消息内容是否为 mbs accept。< /p>

等待函数

然后,它使用我们提供的检查等待消息。阅读有关 wait_for 函数 here 的更多信息。

PS: 抱歉回复晚了,如果您有任何不可预见的错误或有疑问,请随时跟进!