因此,您可以使用这个事实将提及搜索到字符串中(Embed.description返回一个字符串类型的对象)。
这样的:
我正在使用discord.py,我试图从命令中获取成员对象,当按下按钮时,它编辑消息和显示的用户mod日志数据。我得到了它的工作,但在一种奇怪的方式,它ping消息中的人,然后事件检查,看看是否有一个ping(交互)我想知道是否有一种方法来查看嵌入内的提及,而不是interaction.message.mentions
有类似的东西,而不是message
?提前感谢!
@client.command()
async def modlogs(ctx, member: discord.Member):
main=discord.Embed(title=" ", description=f"{ctx.author.mention} please use the buttons below to navigate {member.mention}'s modlogs.", color=0x76dba8)
main.set_author(name=f"{member}", icon_url = member.avatar_url)
ram_member = member
await ctx.send(f"{member.mention}",
embed = main,
components=[[
Button(style=ButtonStyle.blue, label="Warnings", custom_id= "blue"),Button(style=ButtonStyle.blue, label="Kicks", custom_id= "red"),Button(style=ButtonStyle.blue, label="Bans", custom_id= "green")
]],
)
@client.event
async def on_button_click(interaction):
print(interaction.message)
if interaction.message.mentions:
if (interaction.message.mentions.__len__() > 0):
for member in interaction.message.mentions:
if collection2.count_documents({"_id": member.id}) == 0:
embed1=discord.Embed(description=f"{member.mention} has no warnings!", color=0xff0000)
embed1.set_author(name="Error")
else:
获取消息
Msg = await Bot.get_message(channel, id)
获取嵌入
看[这个问题][1]的第一个答案。Emb = discord.Embed.from_data(Msg.embeds[0])
获取字段
请看[这个问题][2]的答案。for field in Emb.fields:
print(field.name)
print(field.value)
获取描述
请看[这个问题][3]的第一个答案。Des = Emb.description
搜索提及
>>> Member.mention in Des
True
搜索提及
以' ' ' @开头!' ' ' '并以' ' '> ' ' '结尾。因此,您可以使用这个事实将提及搜索到字符串中(Embed.description返回一个字符串类型的对象)。
这样的:
Men = Des[Des.find("<@!"):Des.find(">")]
UserID = int(Men[3:])
Member = ctx.fetch_user(UserID)
<标题>链接- Discord.py get message embed
- 如何对齐discord.py嵌入消息中的字段
- discord.py检查嵌入标题 内容
- 我如何在discord.py中提到使用user's id的用户? 在结论h1>