0

When i run this code, it raises a 403 Forbidden exception : Cannot send messages to this user. How can i bypass that and so dm banned & kicked users ?

if user.dm_channel == None:
    await user.create_dm()
await user.dm_channel.send(
    content=f"You have been kicked from {server} by <@{message.author.id}> (reason : {splited[2]})")
Wafelack
  • 13
  • 1
  • 3

3 Answers3

1

Try sending a message right before banning the user.

okay
  • 145
  • 1
  • 10
1

Send the message to the user's DM channel before you kick them.

@client.command()
async def kick(ctx, user: discord.Member, *, reason=None):
  if user.dm_channel == None:
      await user.create_dm()
  await user.dm_channel.send(
      content=f"You have been kicked from {ctx.guild} by {ctx.message.author}\nReason: {reason} ")
  await user.kick(reason=reason)
Jawad
  • 1,971
  • 1
  • 7
  • 17
0

You can't. Discord bots are only able to send DM's to users they share at least one server with, so if someone was kicked/banned from the only mutual server, your bot will not be able to send them any messages.

stijndcl
  • 5,294
  • 1
  • 9
  • 23