@Eirvairdre

Как исправить AttributeError: 'Client' object has no attribute 'command'?

Код:
import discord
from discord.ext import commands
from discord import utils
from discord.ext.commands import Bot
intents = discord.Intents.all()
client = discord.Client(intents = intents)
bot = commands.Bot(command_prefix = prefix, intents=intents)

@client.event
async def on_member_join(member):
    role = discord.utils.get(member.guild.roles, id=933753064681246741)
    print('user joined the server')
    await member.add_roles(role)


@client.event
async def on_ready():
    print('Бот в работе')
@client.command()
async def help(ctx):
    emb = discord.Embed(title=';fact')
    emb.add_field(name='----'.format(prefix), value = 'by bot')
    await ctx.send(embed = emb)
    emb = discord.Embed(title=';clear')
    emb.add_field(name='Очищает историю сообщений'.format(prefix), value = 'by bot')
    await ctx.send(embed = emb)
    await ctx.message.delete()
  • Вопрос задан
  • 1177 просмотров
Решения вопроса 1
Vindicar
@Vindicar
RTFM!
На кой огурец тебе И экземпляр Client И экземпляр Bot?
Ты вообще документацию на discord.py читал?
class discord.ext.commands.Bot
Represents a discord bot.
This class is a subclass of discord.Client and as a result anything that you can do with a discord.Client you can do with this bot.

Выделение моё. Bot умеет всё, что умеет Client, так что Client имеет смысл использовать ТОЛЬКО если тебе не нужны фичи и поведение именно Bot.

Ну и фарш в импортах тоже хорош.
from discord.ext import commands
from discord.ext.commands import Bot

А потом всё равно используешь commands.Bot.
Давай, приводи код в порядок.
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы