【问题标题】:Discord.py MassdmDiscord.py Massdm
【发布时间】:2021-02-04 19:12:37
【问题描述】:

我需要这个 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 版本是多少?
  • 最新,我 3 天前刚刚更新。

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


【解决方案1】:

在新版本的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 references

【讨论】:

    【解决方案2】:

    这是完整的代码。

    @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}")
    

    【讨论】:

    • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
    猜你喜欢
    • 2021-01-07
    • 2021-03-24
    • 2020-09-18
    • 2020-09-30
    • 2019-02-07
    • 2020-05-06
    • 2020-09-16
    • 2020-05-22
    • 1970-01-01
    相关资源
    最近更新 更多