Discord.py 重写让机器人响应 DM
Discord.py rewrite have bot respond to DMs
我正在尝试让我的机器人响应接受规则的 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
这是我的查询代码:
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 重写文档 here。
检查函数
然后,check
函数首先检查消息发送的频道是否为DM,检查作者是否为会员,并检查消息内容是否为mbs accept
.
等待函数
然后,它 waits_for 消息,使用我们提供的检查。阅读有关 wait_for
函数 here.
的更多信息
PS: 抱歉回复晚了,如有任何不可预见的错误或疑问,欢迎随时跟进!
我正在尝试让我的机器人响应接受规则的 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
这是我的查询代码:
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 重写文档 here。
检查函数
然后,check
函数首先检查消息发送的频道是否为DM,检查作者是否为会员,并检查消息内容是否为mbs accept
.
等待函数
然后,它 waits_for 消息,使用我们提供的检查。阅读有关 wait_for
函数 here.
PS: 抱歉回复晚了,如有任何不可预见的错误或疑问,欢迎随时跟进!