@LebVit

Почему бот подключается, но не распознает команды?

intents = discord.Intents.all() 
intents.members = True 

bot = discord.Client(command_prefix='!', intents=intents, help_command=None) 

@bot.event
async def on_message(message):
    if message.author == bot.user:
        return
    if message.content.startswith('!'):
        if message.content == '!refresh':
            refresh()
        else:
            response = get_city(message.content)
            await message.channel.send(response)


bot.run(TOKEN)


Вывод: [2022-09-27 22:16:06] [INFO ] discord.gateway: Shard ID None has connected to Gateway (Session ID: 1f2a8f4e21d2d822d54961f3e6eec05f).
  • Вопрос задан
  • 125 просмотров
Решения вопроса 1
LIREN
@LIREN
Пунктумофоб
для создания команд лучше использовать @bot.command() ...
+ commands.Bot, а не discord.Client.

from discord.ext import commands

intents = discord.Intents.all()

command_prefix = "!"
bot = commands.Bot(
    command_prefix = command_prefix, 
    intents = intents, 
    help_command = None
)

COMMANDS = [
    "refresh"
]

@bot.event
async def on_message(message):
    if (message.author == bot.user):
        return

    elif (message.content.startswith(command_prefix)):
        if (message.content in command_prefix + COMMANDS):
            pass
        else:
            response = get_city(message.content)
            await message.channel.send(response)

@bot.command()
async def refresh(ctx):
    refresh()

bot.run(TOKEN)
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

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

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