【问题标题】:How to send a single message to multiple tagged users? (discord.py)如何将一条消息发送给多个标记的用户? (discord.py)
【发布时间】:2021-05-01 01:29:05
【问题描述】:

我的机器人中有一个名为“spam”的命令,这样当有人执行“.spam”时,它会发送一个嵌入警告,不要发送垃圾邮件。我已经能够让机器人在提及用户的同时发送嵌入。但是,当我执行“.spam @user1 @user2”时,它确实提到了两个用户,但也发送了两次嵌入,一次用于 user1,另一次用于 user2。

如何才能使仅发送 1 条消息,并提及用户数量? 任何帮助将不胜感激!谢谢。

这是我在垃圾邮件齿轮中的代码:

@commands.command()
    async def spam(self, ctx, *members: discord.Member):
        if members is None:
            embed = discord.Embed(
                title='',
                description='Please do not spam the chat.',
                colour=discord.Colour.blue()
            )
            embed.set_footer(text='')
            embed.set_author(name='Mod says:',
                             icon_url='https://cdn.discordapp.com/avatars/745674627845587004/834f65d2747b1bb8806d12e3791c36bd.webp?size=1024')
            await ctx.send(embed=embed)

        else:
            embed = discord.Embed(
                title='',
                description='Please do not spam the chat.',
                colour=discord.Colour.blue()
            )
            embed.set_footer(text='')
            embed.set_author(name='Mod says:',
                             icon_url='https://cdn.discordapp.com/avatars/745674627845587004/834f65d2747b1bb8806d12e3791c36bd.webp?size=1024')
            for member in members:
                await ctx.send(member.mention, embed=embed)

【问题讨论】:

    标签: python bots discord.py discord.py-rewrite


    【解决方案1】:
    for member in members:
        await ctx.send(member.mention, embed=embed)
    

    是问题所在。我会做这样的事情,虽然这不是最好的解决方案。

    await ctx.send(" ".join([member.mention for member in members]), embed=embed)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-21
      • 1970-01-01
      • 2018-01-15
      • 2021-03-21
      • 2021-02-24
      • 2021-03-11
      • 2019-04-14
      • 2021-07-18
      相关资源
      最近更新 更多