【问题标题】:discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'ClientUser' object has no attribute 'create_dm'discord.ext.commands.errors.CommandInvokeError:命令引发异常:AttributeError:'ClientUser'对象没有属性'create_dm'
【发布时间】:2021-01-30 08:11:59
【问题描述】:

这个命令应该发给服务器中的每个人。这是我的代码:

bot = commands.Bot(command_prefix = prefix)
@bot.command(name = 'massdm', pass_context=True)
async def dm(ctx, message):
    guild = ctx.message.guild
    for member in guild.members:
        await asyncio.sleep(0)
        await member.send(message)
        await ctx.send("Sent message")

【问题讨论】:

  • 您应该将错误消息添加到您的帖子中,而不是说出现错误。
  • ^^^ 它没有在控制台中给我任何错误消息

标签: python discord discord.py


【解决方案1】:

我没有看到您的错误,但我认为await ctx.send_message(member, message) 行导致了错误。没有像ctx.send_message 这样的东西。您可以使用ctx.sendchannel.sendmember.send。如果您想发送 dm,请使用member.send。所以你可以这样做:

@bot.command(name = 'massdm', pass_context=True)
async def dm(ctx, message):
    guild = ctx.message.guild
    for member in guild.members:
        await asyncio.sleep(0)
        try:
            await member.send(message)
            await ctx.send("Sent message")
        except:
            await ctx.send("Error")

【讨论】:

  • 稍微更改了我的代码,现在我收到一条新的错误消息。上面写的,想看的可以看一下。
  • 您能否在问题中添加如何定义bot
  • 是的,添加了。
  • 您可以将参数名称更改为 message 以外的其他名称,还是可以将 guild=ctx.message.guild 更改为 guild=ctx.guild
  • 同样的错误 discord.ext.commands.errors.CommandInvokeError:命令引发异常:AttributeError:'ClientUser'对象没有属性'create_dm'
猜你喜欢
  • 2021-12-07
  • 2022-01-25
  • 1970-01-01
  • 1970-01-01
  • 2022-01-05
  • 2021-02-05
  • 1970-01-01
  • 2021-12-04
  • 2021-07-18
相关资源
最近更新 更多