Why my cog file don't want import to main.py?

Viewed 21

Hi i've tried to wirte my own music bot but aperantly i can't all the time i have problem

Traceback (most recent call last):
  File "C:\Users\fabia\Desktop\bot muzyka\main.py", line 7, in <module>
    from help_cog import help_cog
  File "C:\Users\fabia\Desktop\bot muzyka\help_cog.py", line 4, in <module>
    class help_cog(commands.cog):
  File "C:\Users\fabia\Desktop\bot muzyka\help_cog.py", line 37, in help_cog
    async def help(self, ctx):
  File "C:\Users\fabia\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\core.py", line 1748, in decorator
    return cls(func, name=name, **attrs)
  File "C:\Users\fabia\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\core.py", line 381, in __init__
    raise TypeError("Aliases of a command must be a list or a tuple of strings.")
TypeError: Aliases of a command must be a list or a tuple of strings.

This is the error

No matter what i do can't fix this cog files are in the same folder tried to change few things nothing works if someone could help me that would be awesome here is my code

Main.py

import discord
from discord.ext import commands
import os 

from music_cog import music_cog

from help_cog import help_cog

bot = commands.bot(command_prefix="!")
bot.add_cog(music_cog(bot))

bot.remove_command("help")

bot.run(os.getenv("TOKEN"))

music_cog.py

import discord
from discord.ext import commands
from youtube_dl import YoutubeDL
 
#Ustawianie bota
class music_cog(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

        self.is_playing = False
        self.is_paused = False

        self.music_queue = []
        self.YDL.OPTIONS = {'format': 'bestaudio', 'noplaylist': 'True'}
        self.FFMPEG_OPTIONS = {'before_options': '-reconnect 1 -reconnected_streamed 1 -reconnect_delay_max 5', 'options': '-vn'}
        
        self.vc = None
# szukanie URL na yt 
        def search_yt(Self, item):
            with youtube_dl(self.YDL_OPTIONS) as ydl:
                try:
                    info = ydl.extract_info("ytserch:%s" % item, download=False)['entries'][0]
                except Exception:
                    return False
                return {'source': info['formats'[0]['url']], 'title': info['title']}
# Nastepna nutka
    def play_next(self):
        if len(self.music_queue) > 0:
            self.is_playing = True

            m_url = self.music_queue[0][0]['source']

            self.music_queue.pop(0)

            self.vc.play(discord.FFmpegPCMAudio(m_url **self.FFMPEG_OPTIONS), after=lambda e: self.play_next())
        else:
            self.is_playing = False

    async def play_music(self, ctx):

        if len(self.music_queue) > 0:
            self.is_playing = True
            m_url = self.music_queue[0][0]['source']

            if self.vc == None or not self.vc.is_connected():
                self.vc = await self.music_queue[0][1].connect()

                if self.vc == None:
                    await ctx.send("Nie moge sie podłączyć do kanału")
                    return
            else:
                await self.vc.move_to(self.music_queue[0][1])

            self.music_queue.pop(0)

            self.vc.play(discord.FFmpegPCMAudio(m_url, **self.FFMPEG_OPTIONS), after=lambda e: self.play_next())

        else:
            self.is_playing = False

    @commands.command(name="play", aliases=["p"], help="Bot odtwarza piosenek z podanego Linku")
    async def play(self, ctx, *args):
        query = " ".join(ArgSpec)

        voice_channel = ctx.author.voice.channel
        if voice_channel is None:
            await ctx.send("Wejdz na kanal a potem zacznij impreze")
        elif self.is_paused:
            self.vc.resume()
        else:
            song = self.search_yt(query)
            if type(song) == type(True):
                await ctx.send("Nie moznna znalezc nutki cos skopales!!!")
            else:
                await ctx.send("Notka dodana do kolejki")
                self.music_queue.append([song, voice_channel])

                if self.is_playing == False:
                    await self.play_music(ctx)

    @commands.command(name="pause", help="pauzuje obecnie odtwarzana nutke")
    async def pause(self, ctx, *args):
        if self.is_playing:
            self.is_playing = False
            self.is_paused = True
            self.vc.pause()
        elif self.is_paused:
            self.is_playing = True
            self.is_paused = False
            self.vc.resume()

    @commands.command(name="resume", aliases=["r"], help="Wznawia zatrzymaną nutke")
    async def resume(self, ctx, *args):
        if self.is_paused:
            self.is_playing = True
            self.is_paused = False
            self.vc.resume()

    @commands.command(name="skip", aliases=["s"], help = "Pomija obecnie grana piosenke")
    async def skip(self, ctx, *args):
        if self.vc != None and self.vc:
            self.vc.stop()
            await self.play_music(ctx)

    @commands.command(name="queue", aliases=["q"], help="Pokazuje wszystkie obecne nutki w kolejce")
    async def queue(self, ctx):
        retval = ""

        for i in range(0, len(self.music_queue)):
            if i > 4: break
            retval += self.music_queue[i][0]['title'] + '\n'

        if retval != "":
            await ctx.send(retval)
        else:
            await ctx.send("Nie ma żadnej nutki w kolejce")

    @commands.command(name="clear", aliases=["c"], help="Zatrzymuje obecnie grana nutke i czyści całą kolejke")
    async def clear(self, ctx, *args):
        if self.vc != None and self.is_playing:
            self.vc.stop()
        self.music_queue = []
        await ctx.send("Kolejka wyczyszczona")
    
    @commands.command(name="leave", aliases=["l"], help="wyrzuca bota z kanału")
    async def leave(self, ctx):
        self.is_playing = False
        self.is_paused = False
        await self.vc.disconnect()

help_cog.py

import discord
from discord.ext import commands

class help_cog(commands.cog):
    def __init__(self, bot):
        self.bot = bot

        self.help_message = 
"""
Komendy:
!help (!h) - Wyświetla wszystkie dostępne komendy bota
!play <link> (!p) - Wyszukuje nutke na yt i odtwarza ja na twoim kanale 
!pause - Pauzuje obecnie odtwarzana nutke
!clear (!c) - Czyści kolejke
!resume (!r) - Wznawia odtwarzanie muzyki
!skip (!s) - Pomija obecna nutke
!queue (!q) - Pokazuje wszystkie nutki w kolejce
!leave (!l) - Wyrzuca bota z kanału
"""

        self.text_channel_text = []

    @commands.Cog.listener()
    async def on_ready(self):
        for guild in self.bot.guilds:
            for channel in guild.text_channels:
                self.text_channel_text.append(channel)

        await self.send_to_all(self.help_message)
    
    async def send_to_all(self, msg):
        for text_channel in self.text_channel_text:
            await text_channel.send(msg)

    @commands.command(name="help", aliases="h", help="Wyświetla wszystkie dostępne komendy bota")
    async def help(self, ctx):
        await ctx.send(self.help_message)
1 Answers

In your help-cog.py your help command has an alias set as "h".

@commands.command(name="help", aliases="h", help="Wyświetla wszystkie dostępne komendy bota")
async def help(self, ctx):
    await ctx.send(self.help_message)

Like the error says, aliases can only be lists or tuples, yours is a string. Change the command to this.

@commands.command(name="help", aliases=["h"], help="Wyświetla wszystkie dostępne komendy bota")
async def help(self, ctx):
    await ctx.send(self.help_message)

It's the same thing except the single string that you inputted is now a single string in an array.

Related