Python discord.ext.commands.errors.CommandInvokeError:命令引发异常:AttributeError:“ClientUser”对象没有属性“create_dm”

Python discord.ext.commands.errors.CommandInvokeError:命令引发异常:AttributeError:“ClientUser”对象没有属性“create_dm”,python,discord,discord.py,Python,Discord,Discord.py,这个命令应该对服务器中的每个人进行DM。这是我的密码: 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)

这个命令应该对服务器中的每个人进行DM。这是我的密码:

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")

我没有看到您的错误,但我假设该行正在等待ctx.send_messagemember,这是导致错误的消息。没有什么能比得上ctx。发送消息。您可以使用ctx.send、channel.send、member.send。如果要发送dm,请使用member.send。因此,您可以:

@bot.commandname='massdm',pass_context=True 异步def dmctx,消息: guild=ctx.message.guild 对于帮会中的成员。成员: 等待asyncio.sleep0 尝试: 等待成员发送消息 等待ctx.sendSent消息 除: 等待ctx.sendError
与其说“获取错误”,不如将错误消息添加到帖子中。^^^^控制台中没有给我任何错误消息稍微更改了我的代码,现在我收到了一条新的错误消息。如果你想看的话,上面写着。你能在你的问题中添加你如何定义机器人吗?是的,添加了它。是否可以将参数名称更改为message以外的名称,或者是否可以将guild=ctx.message.guild更改为guild=ctx.guild?相同错误discord.ext.commands.errors.CommandInvokeError:命令引发异常:AttributeError:'ClientUser'对象没有属性'create\dm'