@ bot.command()AttributeError:“客户端”对象没有属性“命令”

时间:2020-05-03 15:45:41

标签: python discord.py discord.py-rewrite

from discord.ext import commands
client = discord.Client(command_prefix='x!')


@client.event
async def on_ready():
    print("Successfully booted the bot up!")


@client.event
async def on_message(message):
    if message.content.find("minecraft") != -1:
        await message.channel.send('@Kerina#4436 ajde majnkraft jebemlite')


@client.command()
async def nwordpass(ctx):
    await ctx.send('Proof of you having the nword pass: https://lh3.googleusercontent.com/1HBSAiHdRdM1UVJJZlOUnMkihkiMOPPYSMTjI5WzHuvDVIBztueZR83rkUiHwIJvrfU')


client.run("NzA2MzE0MTc3NjQzNDEzNTY1.Xq4cYw.A-6MruzAgtLC1maW4VVIB2HlFM4")

为什么不起作用? 我尝试了几乎所有常见的修复方法,但是都没有得到任何积极的结果

2 个答案:

答案 0 :(得分:1)

您需要使用Bot中的discord.ext.commands

from discord.ext import commands
client = commands.Bot(command_prefix='x!')


@client.event
async def on_ready():
    print("Successfully booted the bot up!")


@client.event
async def on_message(message):
    if message.content.find("minecraft") != -1:
        await message.channel.send('@Kerina#4436 ajde majnkraft jebemlite')
    await client.process_commands(message)


@client.command()
async def nwordpass(ctx):
    await ctx.send('Proof of you having the nword pass: https://lh3.googleusercontent.com/1HBSAiHdRdM1UVJJZlOUnMkihkiMOPPYSMTjI5WzHuvDVIBztueZR83rkUiHwIJvrfU')

我还添加了await client.process_commands(message)行,以便处理您的命令。

答案 1 :(得分:-1)

https://discordpy.readthedocs.io/en/latest/ext/commands/extensions.html#id1处的示例代码表明正确的代码应如下所示:

@commands.command()
async def nwordpass(ctx):
    await ctx.send('Proof of you having the nword pass: https://lh3.googleusercontent.com/1HBSAiHdRdM1UVJJZlOUnMkihkiMOPPYSMTjI5WzHuvDVIBztueZR83rkUiHwIJvrfU')

也就是说,command()装饰器是在commands模块上定义的,而不是在Client实例对象上定义的。