@BacMartin

Не запускается дискорд бот, что делать?

import discord
import config
from discord.ext import commands

client = discord.Client(intents=discord.Intents.default())
client.run(config.TOKEN)
intents = discord.Intents.default()
intents.message_content = True

bot = commands.Bot(command_prefix='/', intents=intents)

@bot.event
async def on_ready():
    print(f'{bot.user.name} has connected to Discord!')

@bot.command(name='ping')
async def ping(ctx):
    await ctx.send(f'{ctx.author.mention} pong!')

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

    if message.content.startswith('$hello'):
        await message.channel.send('Hello!')

@bot.event
async def on_message(message):
    if message.author != bot.user:
        await ctx.send("Hi")
        
@client.event
async def on_message(message):
    if message.author == client.user:
        return

    if message.content == 'Привет':
        await message.channel.send('Hello human!')
        
bot.run(config.TOKEN)


Вот мой код для бота в дискорде

Помогите пожалуйста, я хочу что бы мой бот отвечал мне в ответ что-либо из этих команд. Токен правильный, вывод в консоли такой:

2022-10-21 19:01:35 INFO discord.client logging in using static token
2022-10-21 19:01:36 INFO discord.gateway Shard ID None has connected to Gateway


MESSAGE CONTENT INTENT Я тоже включил, не знаю что вообще не так....
  • Вопрос задан
  • 140 просмотров
Пригласить эксперта
Ответы на вопрос 1
Vindicar
@Vindicar
RTFM!
Ну для начала неплохо бы прочитать документацию!
client = discord.Client(intents=discord.Intents.default())
bot = commands.Bot(command_prefix='/', intents=intents)

Вот на кой тебе сразу и экземпляр Client, и экземпляр Bot, если Bot умеет всё, что умеет Client?
При этом что ты запускаешь? Сразу же client.run(config.TOKEN)
Т.е. до всего, что после этой строки выполнение вообще не доходит, так как run() уходит в вечный цикл работы бота.

Убери всё, что связано с client. Если тебе так надо on_ready() - декорируй его через @bot.event.

Впрочем, учитывая, что ты не осилил оформить код в редакторе текста на сайте, чтобы сделать твой код читаемым...
Ответ написан
Комментировать
Ваш ответ на вопрос

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

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