gpt4 book ai didi

python - discord.py 检查嵌入标题的内容

转载 作者:行者123 更新时间:2023-12-04 08:19:51 27 4
gpt4 key购买 nike

我正在尝试做什么:我正在用我的 discord.py 机器人发出谜语命令。每次有人运行新谜语的命令时,它都会删除最近固定的消息(所述消息的作者是机器人)并固定新消息。我试图让机器人在嵌入的标题中查找特定关键字,而不是依赖固定消息是否由机器人发送。

问题:我还没有找到检查嵌入标题内容的方法。我发现与我的问题最相关的唯一问题是an on_message() event。 , 但我不太确定如何合并它。

代码:

@client.command(aliases=["riddle"],pass_context=True)
@commands.guild_only()
@has_permissions(manage_messages=True)
async def rid(ctx, prize=None, *, rid=None):
if prize == None and rid == None:
await ctx.send('Format: `bl!riddle "cool prize" Sometimes it\'s brown and sticky, what is it?`')
elif prize is not None and rid == None:
await ctx.send('Format: `bl!riddle "a nice prize" Fluffy like candy but not a cloud, what am I?`')
elif prize is not None and rid is not None:
embed = discord.Embed(title, "Today's Riddle: ", description=rid, color=0x8d78d9) # The embed title the bot would read
embed.set_footer(text=f"Prize: {prize} | Host: {ctx.message.author}")
try:
await ctx.message.delete()
except:
pass
pinner = await ctx.send(embed=embed)
channel = ctx.channel
pins = await channel.pins()
x = 1
while x is not 0:
for message in pins:
if message.author.id == 733237477170741280: # this is what I want to replace
await message.unpin()
x = x - 1
else:
continue
if x == 0:
break
await pinner.pin()

图片:

How the embed looks

这是嵌入的样子。

我看过的其他问题:

最佳答案

discord.Embed对象具有属性 titledescription .通过这些,您可以访问嵌入的内容。

@client.command(aliases=["riddle"],pass_context=True)
@commands.guild_only()
@has_permissions(manage_messages=True)
async def rid(ctx, prize=None, *, rid=None):
if prize == None and rid == None:
await ctx.send('Format: `bl!riddle "cool prize" Sometimes it\'s brown and sticky, what is it?`')
elif prize is not None and rid == None:
await ctx.send('Format: `bl!riddle "a nice prize" Fluffy like candy but not a cloud, what am I?`')
elif prize is not None and rid is not None:
embed = discord.Embed(title="Today's Riddle: ", description=rid, color=0x8d78d9)
embed.set_footer(text=f"Prize: {prize} | Host: {ctx.message.author}")
embed_title = embed.title
embed_desc = embed.description
...

编辑

为了从消息中获取嵌入对象,您可以使用message.embeds。这将为您返回消息所具有的嵌入列表。

关于python - discord.py 检查嵌入标题的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65548178/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com