0

I wanted to make an error command for my code, that gets shown when the dms are turned off or the user wasn't found, here's my code:

@client.command()
async def DM(ctx, user: discord.User, *, message=None):
        message = message or "DM message to be sent"
        await user.send(message)
Takaso
  • 39
  • 6

1 Answers1

0

It is as simple as:

You can read the docs here. It will raise a Forbidden error if you can't send the message.

@client.command()
async def DM(ctx, user: discord.User, *, message=None):
        message = message or "DM message to be sent"
        try:
            await user.send(message)
        except: 
            await ctx.send("Failed to send Dm")
Axisnix
  • 2,822
  • 5
  • 19
  • 41