【问题标题】:Discord.py not sending dm?Discord.py 不发送 dm?
【发布时间】:2021-04-16 12:50:45
【问题描述】:
#MassDM Command
@bot.command()
async def massdm(ctx, msg):
    await ctx.message.delete()
    show_cursor()
    wipeinput = input(Fore.RED+"Are you sure you want to mass dm? (WARNING: This happens really fast so it will probably flag your account)(y or n): ")
    hide_cursor()
    if wipeinput == "y" or wipeinput == "Y":
        for user in ctx.guild.members:
            if user != bot.user:
                try:
                    channel = await user.create_dm()
                    await channel.send(msg)
                    print(Fore.GREEN + f'Sent to user "{user.name}"')
                except:
                    print(Fore.YELLOW + f'Failed to DM user "{user.name}"')
                    pass
        print(Fore.GREEN+"Finished")

当我运行它时,它只是说“完成”并且没有做任何事情。当我删除尝试/除了它没有错误?我认为我已经设置了所有正确的意图

【问题讨论】:

  • 它只有在你拥有它看起来像的服务器时才有效,可以修复吗?
  • 我认为这可能是 Intent 的问题,您启用了哪些 Intent?
  • intents = discord.Intents().all()

标签: python discord discord.py dm


【解决方案1】:

你在这行犯了一个错误:

wipeinput = input(Fore.RED+"Are you sure you want to mass dm? (WARNING: This happens really fast so it will probably flag your account)(y or n): ")

您似乎正在等待回复。方法是使用wait_for 函数。你应该把它改成这样:

await ctx.send("Are you sure you want to mass dm? (WARNING: This happens really fast so it will probably flag your account)(y or n)?")

wipeinput = bot.wait_for('message')  # You can add another parameter to check if the input is valid and what you want.

另外,我不确定show_cursor()hide_cursor() 是什么功能。它们也可能导致某些东西无法正常工作。

编辑:(感谢 IPSDSILVA 指出这一点)尽管我提供的代码并未围绕帖子中的问题,但代码可能会导致您的代码无法工作

【讨论】:

  • 对不起,我不明白。问题是它没有发送 dm 消息。这能解决什么问题?
  • 虽然代码不是围绕 DM 展开的(在这篇文章中),但如果代码有问题,程序可能会出现故障。
【解决方案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}")

【讨论】:

    猜你喜欢
    • 2021-08-07
    • 2021-05-06
    • 1970-01-01
    • 2021-12-24
    • 2021-07-15
    • 1970-01-01
    • 1970-01-01
    • 2022-01-11
    • 2021-04-26
    相关资源
    最近更新 更多