我想为我的代码创建一个错误命令,当 dms 关闭或找不到用户时显示,这是我的代码:
@client.command()
async def DM(ctx, user: discord.User, *, message=None):
message = message or "DM message to be sent"
await user.send(message)
我想为我的代码创建一个错误命令,当 dms 关闭或找不到用户时显示,这是我的代码:
@client.command()
async def DM(ctx, user: discord.User, *, message=None):
message = message or "DM message to be sent"
await user.send(message)
它很简单:
您可以在此处阅读文档。如果您无法发送消息,它将引发 Forbidden 错误。
@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")