#how to have music in a bot
1 messages · Page 1 of 1 (latest)
#help-other message
Is there any other thing that is in disnake library and not any other library
Pertaining to...
?
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
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.
Yeah but I don't understand what's wrong in the code
The error tells you.
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]
TypeError: __init__() missing 1 required keyword-only argument: 'intents'
pretty easy to figure out what's wrong.
I don't understand how can i specify the intents
Then I suggest you read the https://guide.disnake.dev
so It's still disnake.Intents?
yup..
did you install disnake?
yep
It does require a lavalink server..
cuz in python there are things that are more complicate than using another programming language
It's not complicated.
You have a server to run a bot.. use it to spin up a lavalink instance
You gotta be kidding me