@ bot.command () AttributeError: у объекта «Клиент» нет атрибута «команда» - PullRequest
0 голосов
/ 03 мая 2020
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 ]

1 голос
/ 03 мая 2020

Вам нужно использовать класс 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), чтобы ваши команды обрабатывались.

0 голосов
/ 03 мая 2020

Пример кода на 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 объектах экземпляра.

...