Discord 机器人寻找来自用户的消息
Discord bot look for message from user
我正在制作一个验证机器人,工作人员必须在验证发送后接受或拒绝用户,并对消息做出反应。但是,如果工作人员拒绝用户,则机器人会询问将发送给用户的原因。问题是,当机器人正在等待工作人员发送原因时,如果在任何其他渠道发送了一条消息,那么机器人将使用该消息作为原因。
elif str(reaction) == "❌":
remove_id(member.id)
await verif_channel.send(":warning: Please provide a reason :warning:")
try:
deny_channel = member.guild.get_channel(889690902359080970)
msg = await self.bot.wait_for("message", timeout=600)
why = msg.content
embed_reason = discord.Embed(
title=":warning: You have been denied! :warning:",
description="You have been denied from the server for the following reason: (You are still allowed to reverify by reacting to the message in <#734570330064028002>) \n\n"
"{}".format(f"Reason: {why}"),
color=int(hex_color, 16))
await member.send(embed=embed_reason)
await verif_channel.send(f"❌ I have denied {member.mention}")
embed2 = discord.Embed(
title="Verification Request",
description=f"Verification request of {member.mention}",
color=int(hex_color, 16)
)
embed2.set_thumbnail(url=member.avatar_url)
embed2.add_field(name="How did you find this server?", value=found, inline=False)
embed2.add_field(name="How old are you?", value=age, inline=False)
embed2.add_field(name="This is a server related question", value=about, inline=False)
embed2.add_field(name="What are you looking to get out of this server?", value=seek, inline=False)
embed2.add_field(name="User was:", value=f"Denied for {why}", inline=False)
embed2.set_author(name=member.name)
embed2.set_footer(text=f"User ID: {member.id}")
channel = member.guild.get_channel(863099566672707594)
await channel.purge(limit=4)
await deny_channel.send(embed=embed2)
except discord.Forbidden:
await verif_channel.send(f"❌ Denied {member.mention}\n"
f"User has blocked DMs")
我正在尝试更改它,以便机器人将在频道中查找对消息做出反应的用户的消息。我尝试了几种不同的方法,但我真的不知道如何获得对消息做出反应的用户的 ID。
检查消息是否由特定人员发送的最佳方法是使用 check function
。请查看下面的代码。
# Define the check function within your code
def check(msg):
return msg.author == reaction.author and not msg.author.bot
# This checks if the author of the message is the author of the ❌ reaction
# AND checks if the message author is a bot or not
msg = await self.bot.wait_for("message", check=check, timeout=600)
有帮助 link(s):
client.wait_for
- discord.py 文档
我正在制作一个验证机器人,工作人员必须在验证发送后接受或拒绝用户,并对消息做出反应。但是,如果工作人员拒绝用户,则机器人会询问将发送给用户的原因。问题是,当机器人正在等待工作人员发送原因时,如果在任何其他渠道发送了一条消息,那么机器人将使用该消息作为原因。
elif str(reaction) == "❌":
remove_id(member.id)
await verif_channel.send(":warning: Please provide a reason :warning:")
try:
deny_channel = member.guild.get_channel(889690902359080970)
msg = await self.bot.wait_for("message", timeout=600)
why = msg.content
embed_reason = discord.Embed(
title=":warning: You have been denied! :warning:",
description="You have been denied from the server for the following reason: (You are still allowed to reverify by reacting to the message in <#734570330064028002>) \n\n"
"{}".format(f"Reason: {why}"),
color=int(hex_color, 16))
await member.send(embed=embed_reason)
await verif_channel.send(f"❌ I have denied {member.mention}")
embed2 = discord.Embed(
title="Verification Request",
description=f"Verification request of {member.mention}",
color=int(hex_color, 16)
)
embed2.set_thumbnail(url=member.avatar_url)
embed2.add_field(name="How did you find this server?", value=found, inline=False)
embed2.add_field(name="How old are you?", value=age, inline=False)
embed2.add_field(name="This is a server related question", value=about, inline=False)
embed2.add_field(name="What are you looking to get out of this server?", value=seek, inline=False)
embed2.add_field(name="User was:", value=f"Denied for {why}", inline=False)
embed2.set_author(name=member.name)
embed2.set_footer(text=f"User ID: {member.id}")
channel = member.guild.get_channel(863099566672707594)
await channel.purge(limit=4)
await deny_channel.send(embed=embed2)
except discord.Forbidden:
await verif_channel.send(f"❌ Denied {member.mention}\n"
f"User has blocked DMs")
我正在尝试更改它,以便机器人将在频道中查找对消息做出反应的用户的消息。我尝试了几种不同的方法,但我真的不知道如何获得对消息做出反应的用户的 ID。
检查消息是否由特定人员发送的最佳方法是使用 check function
。请查看下面的代码。
# Define the check function within your code
def check(msg):
return msg.author == reaction.author and not msg.author.bot
# This checks if the author of the message is the author of the ❌ reaction
# AND checks if the message author is a bot or not
msg = await self.bot.wait_for("message", check=check, timeout=600)
有帮助 link(s):
client.wait_for
- discord.py 文档