discord bot не выполняет команды
ВОПРОС ПО ПОВОДУ ДИСКОРД БОТА. вот как объединить(если так можно выразиться) @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 шт):
Автор решения: q r t s
→ Ссылка
Ваш бот не отвечает на сообщения, так как дальше 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)