Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
547 views
in Technique[技术] by (71.8m points)

python - Discord.py not sending dm?

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

When I run this it just says "Finished" and doesnt do anything. when i remove the try/except it gives not error? I have all the proper intents set up i think


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You're making a mistake in this line:

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

It seems that you're waiting for a response. The way to do that is with the wait_for function. You should change that to this:

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.

In addition, I am unsure of what the functions show_cursor() and hide_cursor() are. They may also be causing something to not work.

EDIT: (Thanks to IPSDSILVA for pointing this out) Even though the code that I gave doesn't revolve around the issue in the post, any issue in the code may cause your code to not work


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...