Search code examples
pythondiscorddiscord.pybots

problem with sending a DM from a Discord bot to a member


so when i try and run this code

@client.command()
async def message(ctx, user: discord.Member, *, message=None):
    message = "hello"
    embed = discord.Embed(title=message)
    await user.send(embed= embed)

which is supposed to send a DM to a member from my server it doesn't work even though i enabled all intents in the script, and it doesn't show any error the bot works like always except the part of sending a DM to a member

it's supposed to show an embed message with the title being'hello'


Solution

  • The code you have provided doesnt make sense you are setting the message to none and then setting it to hello here is the correct code

    @client.command()
    async def message(ctx, user: discord.Member, *, message=""):
        embed = discord.Embed(title=message)
        await user.send(embed= embed)
    

    example message

    !message @YourDiscord Hello
    

    with ! being the prefix and YourDiscord being your name