【问题标题】:Discord.py DM ALL doesn't send message to everyoneDiscord.py DM ALL 不会向所有人发送消息
【发布时间】:2022-01-11 05:46:12
【问题描述】:

所以我有这个代码。它应该向服务器中的每个人发送消息。它不会 DM 所有人,而只会尝试 DM 运行在代码上的机器人,因为这是不可能的,所以它失败了。

@client.command()
async def adm(ctx, *, message):
    await ctx.message.delete()
    for user in ctx.guild.members:
        try:
            await user.send(message)
            print(f"Sent {user.name} a DM.")
        except:
            print(f"Couldn't DM {user.name}.")
    print("Sent all the server a DM.")

【问题讨论】:

  • 您需要启用会员意图。
  • 我该怎么做?

标签: python discord discord.py


【解决方案1】:

这可能是因为您没有启用 Privileged Gateway 意图,并且您的机器人无法获取所有成员。在 Bot 部分的Discord Developer 站点上启用Server Members Intent

然后,将其添加到您的代码中:

intents = discord.Intents.default()
intents.members = True

client = commands.Bot(command_prefix="!", intents=intents)

【讨论】:

    猜你喜欢
    • 2021-05-06
    • 2021-05-03
    • 2021-12-24
    • 2021-04-16
    • 2020-09-09
    • 1970-01-01
    • 2021-12-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多