简体   繁体   中英

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. 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.

How do I make it so that only 1 message gets sent, with the amount of users mentioned? 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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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