当我运行此代码时,它会引发 403 Forbidden 异常:无法向该用户发送消息。我怎样才能绕过那个等 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]})")
当我运行此代码时,它会引发 403 Forbidden 异常:无法向该用户发送消息。我怎样才能绕过那个等 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,因此如果有人被踢出/禁止进入唯一的共同服务器,您的机器人将无法向他们发送任何消息。
尝试在禁止用户之前立即发送消息。