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

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

4

2 回答 2

0

这是一切正常的完整代码。

@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}")
于 2022-02-18T03:18:06.277 回答
0

你在这一行犯了一个错误:

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

于 2021-01-11T15:28:41.953 回答