0

ВОПРОС ПО ПОВОДУ ДИСКОРД БОТА. вот как объединить(если так можно выразиться) @bot.command() и @bot.event я хочу чтобы бот реагировал на и на обычные сообщения и на команды

import discord
from discord.ext import commands

intents = discord.Intents.all()
intents.message_content = True
bot = commands.Bot(command_prefix="!", intents=intents)
@bot.command()
async def test(ctx):
    await ctx.send(f'123')
@bot.event
async def on_message(message):
  print(f'Message by {message.author}: {message.content}')
bot.run(token)
1

1 ответ 1

3

Ваш бот не отвечает на сообщения, так как дальше on_message он не может проверить команды. Добавьте после print(..) Строку

await bot.process_commands(ctx)

Полный код:

import discord
from discord.ext import commands

bot = commands.Bot(command_prefix="!", intents=discord.Intents.all())

@bot.event
async def on_message(ctx):
    print(f'Message by {ctx.author}: {ctx.content}')

    await bot.process_commands(ctx)

@bot.command()
async def test(ctx):
    await ctx.send('Это тестовая команда.')

bot.run(token)
1
  • 1
    Если вам помог мой ответ, не могли бы вы отметить его галочкой?
    – q r t s
    22 дек 2022 в 14:27

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.