尝试对禁止的用户使用DM时引发禁止的异常Discord.py

问题描述

运行此代码时,它引发403禁止的异常:无法向该用户发送消息。我如何绕过它,从而使dm被禁止和踢用户

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]})")

解决方法

在踢他们之前将消息发送到用户的DM频道。

@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)
,

不能。 Discord僵尸程序只能向与其共享至少一台服务器的用户发送DM,因此,如果有人被踢出/禁止了唯一的共同服务器,则您的僵尸程序将无法向他们发送任何消息。

,

在禁止用户之前尝试发送消息。