#how to have music in a bot

1 messages · Page 1 of 1 (latest)

bleak grotto
#

I tried with the guide but I couldn't install FFMPEG can somebody help me or give an example of a bot that has the feature to play something from youtube or spotify?

stoic mantle
#

#help-other message

bleak grotto
#

Is there any other thing that is in disnake library and not any other library

stoic mantle
#

Pertaining to...

bleak grotto
#

?

#

import wavelink
from discord.ext import commands

class Bot(commands.Bot):

def __init__(self):
    super().__init__(command_prefix='>?')

async def on_ready(self):
    print('Bot is ready!')

class Music(commands.Cog):
"""Music cog to hold Wavelink related commands and listeners."""

def __init__(self, bot: commands.Bot):
    self.bot = bot

    bot.loop.create_task(self.connect_nodes())

async def connect_nodes(self):
    """Connect to our Lavalink nodes."""
    await self.bot.wait_until_ready()

    await wavelink.NodePool.create_node(bot=bot,
                                        host='0.0.0.0',
                                        port=2333,
                                        password='YOUR_LAVALINK_PASSWORD')

@commands.Cog.listener()
async def on_wavelink_node_ready(self, node: wavelink.Node):
    """Event fired when a node has finished connecting."""
    print(f'Node: <{node.identifier}> is ready!')

@commands.command()
async def play(self, ctx: commands.Context, *, search: wavelink.YouTubeTrack):
    """Play a song with the given search query.

    If not connected, connect to our voice channel.
    """
    if not ctx.voice_client:
        vc: wavelink.Player = await ctx.author.voice.channel.connect(cls=wavelink.Player)
    else:
        vc: wavelink.Player = ctx.voice_client

    await vc.play(search)

bot = Bot()
bot.add_cog(Music(bot))
bot.run("token")

This says intents is required

stoic mantle
#

well yeah..

#

They're always required.

#

-d disnake.Intents

buoyant zincBOT
#

class disnake.Intents(value=None, **kwargs)```
Wraps up a Discord gateway intent flag.

Similar to [`Permissions`](https://docs.disnake.dev/page/api.html#disnake.Permissions "disnake.Permissions"), the properties provided are two way. You can set and retrieve individual bits using the properties as if they were regular bools.

To construct an object you can pass keyword arguments denoting the flags to enable or disable. Arguments are applied in order, similar to [`Permissions`](https://docs.disnake.dev/page/api.html#disnake.Permissions "disnake.Permissions").

This is used to disable certain gateway features that are unnecessary to run your bot. To make use of this, it is passed to the `intents` keyword argument of [`Client`](https://docs.disnake.dev/page/api.html#disnake.Client "disnake.Client").

New in version 1.5.
bleak grotto
#

Yeah but I don't understand what's wrong in the code

stoic mantle
#

The error tells you.

bleak grotto
#
Traceback (most recent call last):
  File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 31, in <module>
    start(fakepyfile,mainpyfile)
  File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 30, in start
    exec(open(mainpyfile).read(),  __main__.__dict__)
  File "<string>", line 50, in <module>
  File "<string>", line 8, in __init__
TypeError: __init__() missing 1 required keyword-only argument: 'intents'

[Program finished]
stoic mantle
#

TypeError: __init__() missing 1 required keyword-only argument: 'intents'

#

pretty easy to figure out what's wrong.

bleak grotto
#

I don't understand how can i specify the intents

stoic mantle
bleak grotto
#

i already know how to do it in disnake

#

Not in wavelink

stoic mantle
#

It's still disnake.

#

wavelink just adds functionality

bleak grotto
#

so It's still disnake.Intents?

stoic mantle
#

yup..

bleak grotto
#

oh okay

#

Now it says name disnake is not defined

stoic mantle
#

did you install disnake?

bleak grotto
#

yep

stoic mantle
#

oh.

#

I mean.. you didn't import disnake

bleak grotto
#

true

#

I fixed

#

Now it says it couldn't make the connection

stoic mantle
#

It does require a lavalink server..

bleak grotto
#

oh no

#

lavalink

#

I'll never have a music bot

#

guess i'll nead to learn js

stoic mantle
#

because?

#

I mean, go for it, but also...why

bleak grotto
#

cuz in python there are things that are more complicate than using another programming language

stoic mantle
#

It's not complicated.

#

You have a server to run a bot.. use it to spin up a lavalink instance