简体   繁体   English

Discord.py 马斯达姆

[英]Discord.py Massdm

i need this Mass Dm to message everyone except the author But i dont really know how to do it...我需要这个 Mass Dm 来给除作者以外的所有人发消息,但我真的不知道该怎么做......

@bot.command()
    async def massdm(self, ctx, *, args=None):
        if args != None:
            members = ctx.guild.members
            for member in members:
                try:
                    await member.send(args)
                    print("'" + args + "' sent to: " + member.name)

                except:
                    print("Couldn't send '" + args + "' to: " + member.name)

        else:
            await ctx.channel.send("A message was not provided.")

In the new version of discord.py(1.5.x), there're some changes about Intents .在新版本的 discord.py(1.5.x) 中, Intents有一些变化。 Intents are like permissions, you need to define it to use some of the things like sending private messages. Intents 就像权限,你需要定义它来使用一些东西,比如发送私人消息。 You have to define it before the bot = discord.Bot() .您必须在bot = discord.Bot()之前定义它。

import discord

intents = discord.Intents().all()
bot = discord.Bot(prefix='', intents=intents)

If you just want to enable to sending private messages, you can do intents = discord.Intents().dm_messages but I suggest you to use discord.Intents().all() .如果您只想启用发送私人消息,您可以执行intents = discord.Intents().dm_messages但我建议您使用discord.Intents().all()

For more information, you can look at the API references .有关更多信息,您可以查看API 参考

Here is the complete code.这是完整的代码。

@client.command(pass_context=True)
async def massdm(ctx):
    await ctx.message.delete()
    for member in list(client.get_all_members()):
        try:
            embed = discord.Embed(title="Test",
                                  description="Test!",
                                  color=discord.Colour.blurple())
            embed.set_thumbnail(
                url="test")
            embed.set_footer(
                text=
                "test"
            )
            await asyncio.sleep(30)
            await member.send(embed=embed)
        except:
            pass
        #await ctx.send(f"Messaged: {member.name}")
        print(f"Messaged: {member.name}")

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

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