【问题标题】:discord.py - Error command with DM memberdiscord.py - DM 成员的错误命令
【发布时间】:2021-05-20 17:22:25
【问题描述】:

我想为我的代码创建一个错误命令,当 dms 关闭或找不到用户时显示,这是我的代码:

@client.command()
async def DM(ctx, user: discord.User, *, message=None):
        message = message or "DM message to be sent"
        await user.send(message)

【问题讨论】:

    标签: python discord syntax-error discord.py dm


    【解决方案1】:

    就这么简单:

    您可以阅读文档here。如果您无法发送消息,它将引发 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")
    

    【讨论】:

      猜你喜欢
      • 2021-05-17
      • 2019-08-22
      • 1970-01-01
      • 1970-01-01
      • 2021-04-30
      • 2020-03-31
      • 2021-03-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多