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