Discord bot 查找来自用户的消息
Posted
技术标签:
【中文标题】Discord bot 查找来自用户的消息【英文标题】:Discord bot look for message from user 【发布时间】:2022-01-14 19:00:50 【问题描述】:我正在制作一个验证机器人,一旦发送验证并对消息做出反应,工作人员必须接受或拒绝用户。但是,如果工作人员拒绝用户,机器人会询问将发送给用户的原因。问题是当机器人正在等待工作人员发送原因时,如果在任何其他渠道发送消息,那么机器人将使用该消息作为原因。
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。
【问题讨论】:
【参考方案1】:检查邮件是否由特定人员发送的最佳方法是使用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)
有用的链接:
client.wait_for
- discord.py 文档
【讨论】:
以上是关于Discord bot 查找来自用户的消息的主要内容,如果未能解决你的问题,请参考以下文章
如何使用 discord.js 从 discord bot 向特定用户发送消息
Discord Bot JS:编辑来自先前斜杠命令交互的回复