python - 尝试 dm 禁止用户时引发禁止异常 (Discord.py)
问题描述
当我运行此代码时,它会引发 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)
推荐阅读
- julia - 匿名函数 Julia - x 的值
- c++ - 六角计算器问题。有人可以再次检查我的代码吗?
- angular - 我如何调用 laravel 护照的忘记密码并使用 angular 8 验证 api?
- node.js - Cloud Function Script 写入所有 uid
- python - 如何在 Python 3 中使用请求绕过单选按钮抓取数据?
- if-statement - 为什么我在 IF 语句上收到 FALSE 值而不是指定值?
- android - 视图寻呼机中的 API 调用
- linux - Linux 脚本,显示所有登录学生的姓名和他们的模拟号码登录数量
- react-native - 如何使用react-native-svg-charts中的工具提示标记触摸值的垂直和水平线获取x和y坐标值
- azure - 如何扩展我的 Log Analytics AzureDiagnostics 日志数据