Discord.py不发送dm?

2024-06-30 13:39:31 发布

您现在位置:Python中文网/ 问答频道 /正文

#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")

当我运行这个程序时,它只是说“完成”,什么也不做。当我删除try/except时,它不会出错吗?我想我已经准备好了所有合适的意图


Tags: ortoyouifbotmsgdmawait
1条回答
网友
1楼 · 发布于 2024-06-30 13:39:31

您在这一行中犯了一个错误:

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指出这一点)即使我给出的代码没有围绕文章中的问题,代码中的任何问题都可能导致代码无法工作

相关问题 更多 >