我决定为我的机器人重写右舷模块的代码。 将除星号反应以外的任何其他反应添加到帖子中,然后将消息发布到右舷时,我遇到问题。
应该如何运行是在帖子中仅添加一个星星表情符号时,它将添加到右舷。
我不确定这是否是简单的迭代,但这是我正在使用的
async def on_reaction_add(self, reaction, member):
for guild in self.bot.guilds:
chan = get(guild.channels, name="starboard")
if chan:
for i in reaction.message.reactions:
if i.emoji == '⭐':
return
if reaction.message.author == member:
return
if reaction.count < 1:
return
embed=discord.Embed(color=0xff8000, description=reaction.message.content)
embed.set_author(name=reaction.message.author.name, icon_url=reaction.message.author.avatar_url)
if len(reaction.message.attachments) > 0:
embed.set_image(url=reaction.message.attachments[0]["url"])
embed.set_footer(text=f"Posted in {reaction.message.channel.name}")
embed.timestamp = dt.datetime.utcnow()
await chan.send("New Star!", embed=embed)
答案 0 :(得分:0)
if i.emoji == '⭐':
return
如果表情符号是星星,请停止协程。我认为您正在寻找更多类似的东西
async def on_reaction_add(self, reaction, member):
chan = get(reaction.message.guild.channels, name="starboard")
if not chan:
return
if reaction.emoji != '⭐': # We only care about stars
return
if reaction.message.author == member:
return
if reaction.count != 1: # Only the first time
return
embed=discord.Embed(color=0xff8000, description=reaction.message.content)
embed.set_author(name=reaction.message.author.name, icon_url=reaction.message.author.avatar_url)
if len(reaction.message.attachments) > 0:
embed.set_image(url=reaction.message.attachments[0].url)
embed.set_footer(text=f"Posted in {reaction.message.channel.name}")
embed.timestamp = dt.datetime.utcnow()
await chan.send("New Star!", embed=embed)
当某人首次使用星星进行反应时,这会向右舷发布消息。目前,如果第一颗星星来自消息作者,则没有多少颗星星可以将其放置在右舷。我把它留给读者作为练习;-)