繁体   English   中英

Discord.py 马斯达姆

[英]Discord.py Massdm

我需要这个 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.")

在新版本的 discord.py(1.5.x) 中, Intents有一些变化。 Intents 就像权限,你需要定义它来使用一些东西,比如发送私人消息。 您必须在bot = discord.Bot()之前定义它。

import discord

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

如果您只想启用发送私人消息,您可以执行intents = discord.Intents().dm_messages但我建议您使用discord.Intents().all()

有关更多信息,您可以查看API 参考

这是完整的代码。

@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