@thetvorog

Дискорд бот на питон не видет команды, почему это может быть?

Когда прописываю команды, дискорд бот не реагирует, а в консоли [2023-08-16 12:08:05] [ERROR ] discord.ext.commands.bot: Ignoring exception in command None
discord.ext.commands.errors.CommandNotFound: Command "help" is not found.
import asyncio
import functools
import itertools
import math
import random
import asyncio
from discord import Activity, ActivityType

import discord
import youtube_dl
from async_timeout import timeout
from discord.ext import commands


    @commands.command(name='join', invoke_without_subcommand=True)
    async def _join(self, ctx: commands.Context):
        """Joins a voice channel."""

        destination = ctx.author.voice.channel
        if ctx.voice_state.voice:
            await ctx.voice_state.voice.move_to(destination)
            return

        ctx.voice_state.voice = await destination.connect()

    @commands.command(name='summon')
    @commands.has_permissions(manage_guild=True)
    async def _summon(self, ctx: commands.Context, *, channel: discord.VoiceChannel = None):
        """Summons the bot to a voice channel.
        If no channel was specified, it joins your channel.
        """

        if not channel and not ctx.author.voice:
            raise VoiceError('Вы не подключены к голосовому каналу. И не указали куда подключаться.')

        destination = channel or ctx.author.voice.channel
        if ctx.voice_state.voice:
            await ctx.voice_state.voice.move_to(destination)
            return

        ctx.voice_state.voice = await destination.connect()

    @commands.command(name='stop', aliases=['disconnect'])
    @commands.has_permissions(manage_guild=True)
    async def _leave(self, ctx: commands.Context):
        """Clears the queue and leaves the voice channel."""

        if not ctx.voice_state.voice:
            return await ctx.send('Чё ебнулся? Бот и так не подключен. Зачем его стопать?')

        await ctx.voice_state.stop()
        del self.voice_states[ctx.guild.id]

    @commands.command(name='volume')
    async def _volume(self, ctx: commands.Context, *, volume: int):
        """Sets the volume of the player."""

        if not ctx.voice_state.is_playing:
            return await ctx.send('Сейчас музыка не играет. Можете включить.')

        if 0 > volume > 100:
            return await ctx.send('Volume must be between 0 and 100')

        ctx.voice_state.volume = volume / 100
        await ctx.send('Громкость изменена на {}%'.format(volume))

    @commands.command(name='now', aliases=['current', 'playing'])
    async def _now(self, ctx: commands.Context):
        """Displays the currently playing song."""

        await ctx.send(embed=ctx.voice_state.current.create_embed())

    @commands.command(name='pause')
    @commands.has_permissions(manage_guild=True)
    async def _pause(self, ctx: commands.Context):
        """Pauses the currently playing song."""

        if not ctx.voice_state.is_playing and ctx.voice_state.voice.is_playing():
            ctx.voice_state.voice.pause()
            await ctx.message.add_reaction('⏯')

bot = commands.Bot('#', description='Крутой бот от Луффича)', intents=discord.Intents.all())
bot.add_cog(Music(bot))
bot.remove_command('help')

пол кода не влезает
  • Вопрос задан
  • 197 просмотров
Пригласить эксперта
Ответы на вопрос 2
Zagir-vip
@Zagir-vip
Web dev, Game dev, app dev, Разработчик на Python!
Документация для меня сделана?
Запоминай:

bot = commands.Bot('#', description='Крутой бот от Луффича)', intents=discord.Intents.all())
bot.add_cog(Music(bot))
bot.remove_command('help')

@bot.command()
async def test():
  ...

bot.start(token)


Чтобы бот видел команды ты должен их ему показать, а ты создаёшь команды через @commands.command(), а должен через @bot.command.

Почему через bot ?
Мы инициализируем бота и записываем его в переменную bot и в дальнейшем изменяем поведение, логику бота. Прописав @bot.command() бот понимает, что он должен запомнить команду для использования в дискорде.
Ответ написан
Комментировать
Vindicar
@Vindicar
RTFM!
Выглядит так, словно ты выдрал кусок кода, который был оформлен как класс-Cog, тупо воткнул его в основной код бота и ожидаешь, что оно волшебным образом само поймёт. Даже отступы не поправил.

Вот что тут скажешь кроме "выучи язык сначала"?
Почитай документацию, как пользоваться когами.
Ответ написан
Комментировать
Ваш ответ на вопрос

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

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