如何使用我的不和谐机器人从旧消息/命令中获取内容?

时间:2021-02-19 13:29:53

标签: python discord discord.py

我目前正在尝试使用命令编辑嵌入。编辑后的嵌入结构清晰。它应该是对建议的评估。为此,我需要作者和他来自上一个命令的建议。如果您有两个命令,是否可以获取旧嵌入的内容并将其传输到编辑后的嵌入?此外,最好仍然计算并在消息中插入反应。 以下是我的工作方法,除了缺少的部分:

    #@commands.cooldown(1, 100, BucketType.user)
    @commands.command(usage="<text>")
    async def suggest(self, ctx, *, text: str = None):
        """This is the command for suggestions."""
        if text is None:
            await ctx.send("**You need to insert a text.**")
            return self.suggest.reset_cooldown(ctx)

        channel1 = self.bot.get_channel(812284187427864616)
        if channel1 == ctx.channel:

            channel = self.bot.get_channel(812283430707920906)
                e = discord.Embed(color=discord.Colour.green())
                e.description = f "**__submitter:__**\n {ctx.author}"
                e.add_field(name="__Suggestion:__", value=f"{text}")
                e.set_thumbnail(url=ctx.message.author.avatar_url)
                e.timestamp = datetime.utcnow()
                e.set_footer(text=f "UID: {ctx.author.id}")
                feedback = await channel.send(embed=e)
                await feedback.add_reaction("✅")
                await feedback.add_reaction("❌")
                await ctx.message.add_reaction("✅")

实际编辑旧嵌入的批准命令,应插入“建议”、“提交者”并计算反应。

    @commands.command()
    async def approve(self, ctx, msg_id: int = None, channel: discord.TextChannel = None):
        if not msg_id:
            channel = self.bot.get_channel(812283430707920906) # the message's channel
            msg_id = 998877665544332211 # the message's id
        elif not channel:
            channel = ctx.channel
        msg = await channel.fetch_message(msg_id)
        embed = discord.Embed()
        embed.title = "Suggestion accepted"
        embed.description = "*Here are all the important information*"
        embed.add_field(name="Results", value="✅: MISSING COUNT / ❌: MISSING COUNT")
        embed.add_field(name="Suggestion", value=f"MISSING SUGGESTION TEXT")
        embed.add_field(name="Submitter:", value=f"MISSING SUBMITTER")
        embed.add_field(name="Approved by:", value=f"{ctx.author.mention}")
        await msg.edit(embed=embed)
        await msg.clear_reactions()

为了计算反应,我会使用类似的东西:

total_count = 0
for r in message.reactions:
    total_count += r.count

编辑: 这是现在以不同方式显示 Suggestion 两次的嵌入。

    @commands.command()
    async def approve(self, ctx, channel: discord.TextChannel, msgID: int):
        try:
            msg = await channel.fetch_message(msgID)
            embed = msg.embeds[0]
            submitter = embed.description[embed.description.find('\n'):]
            suggestion = embed.fields[0].value

            embed.title = "Suggestion accepted"
            embed.description = "*Here are all the important information*"
            embed.add_field(name="Results", value="✅: Test/ ❌: Test", inline=False)
            embed.add_field(name="Suggestion", value=f"{suggestion}", inline=False)
            embed.add_field(name="Submitter", value=f"{submitter}", inline=False)
            embed.add_field(name="Approved by", value=f"{ctx.author.mention}", inline=False)
            await msg.edit(embed=embed, reference=msgID)
            await msg.clear_reactions()
        except:
            pass

1 个答案:

答案 0 :(得分:0)

part of 'app_pages.dart'; // DO NOT EDIT. This is code generated via package:get_cli/get_cli.dart abstract class Routes { static const HOME = _Paths.HOME; } abstract class _Paths { static const HOME = '/home'; } 您可以使用获取的消息来获取有关它的详细信息。

msg = await channel.fetch_message(msg_id)

参考资料: fetch_message embeds message

相关问题