简体   繁体   English

如何将一条消息发送给多个标记的用户? (discord.py)

[英]How to send a single message to multiple tagged users? (discord.py)

I have a command called "spam" in my bot such that when someone does ".spam" it sends an embed warning not to spam.我的机器人中有一个名为“spam”的命令,这样当有人执行“.spam”时,它会发送一个嵌入警告,不要发送垃圾邮件。 I have been able to make the bot send the embed along with mentioning a user.我已经能够让机器人在提及用户的同时发送嵌入。 However, when I do ".spam @user1 @user2" it does mention the two users, but sends the embed twice too, once for user1, and the other for user2.但是,当我执行“.spam @user1 @user2”时,它确实提到了两个用户,但也发送了两次嵌入,一次用于 user1,另一次用于 user2。

How do I make it so that only 1 message gets sent, with the amount of users mentioned?如何使仅发送 1 条消息,并提及用户数量? Any help would be highly appreciated.任何帮助将不胜感激。 Thank you.谢谢你。

This is my code in the spam cog:这是我在垃圾邮件齿轮中的代码:

@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)
for member in members:
    await ctx.send(member.mention, embed=embed)

Is the problem.是问题。 I would do something like this, although this is not the best solution.我会做这样的事情,虽然这不是最好的解决方案。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM