self.bot.music = lavalink.Client(self.bot.user.id) AttributeError: ‘NoneType’ object has no attribute ‘id’

  discord.py, python

I wanted to write a music bot for our discord with friends, took the code from the lavalink github and changed it a little, but the error is not where I changed it, but in the most obscure place)

Error: self.bot.music = lavalink.Client(self.bot.user.id)
AttributeError: ‘NoneType’ object has no attribute ‘id’

code from music.py:

import os
from discord.ext import commands
from discord.utils import get
import lavalink

class Music(commands.Cog):

    def __init__(self, bot):
        self.bot = bot
        self.bot.music = lavalink.Client(self.bot.user.id)
        self.bot.music.add_node('localhost', 7000, 'testing', 'na', 'music-node')
        self.bot.add_listener(self.bot.music.voice_update_handler, 'on_socket_response')
        self.bot.music.add_event_hook(self.track_hook)

    @commands.command(name='join')
    async def play(self, ctx, *, query):
        if ctx.author.voice is None:
            return
            await ctx.send(f'`[MUSIC]`: {ctx.author.mention}, вы не находитесь в канале!')
        else:
            channel = ctx.author.voice.channel

        await channel.connect()

        try:
            player = self.bot.music.player_manager.get(ctx.guild.id)
            query = f'ytsearch:{query}'
            results = await player.node.get_tracks(query)
            tracks = results['tracks'][0:10]
            i = 0
            query_result = ''

            for track in tracks:
                i = i + 1
                query_result = query_result + f'{i}) {track["info"]["title"]} - {track["info"]["uri"]}n'

            embed = discord.Embed(
                description=query_result,
                color=0x000000
            )

            await ctx.channel.send(embed=embed)

            def check(m):
                return m.author.id == ctx.author.id

            response = await self.bot.wait_for('message', check=check)
            track = tracks[int(response.content)-1]

            player.add(requester=ctx.author.id, track=track)

            if not player.is_playing:
                await player.play()

        except Exception as error:
            print(error)
      
    async def track_hook(self, event):
        if isinstance(event, lavalink.events.QueueEndEvent):
            guild_id = int(event.player.guild_id)
            await self.connect_to(guild_id, None)
          
    async def connect_to(self, guild_id: int, channel_id: str):
        ws = self.bot._connection._get_websocket(guild_id)
        await ws.voice_state(str(guild_id), channel_id)

def setup(bot):
    bot.add_cog(Music(bot))

Source: Python Questions

LEAVE A COMMENT