From 13c58c5741020c89003ea2b4bfca2ca2afd939db Mon Sep 17 00:00:00 2001
From: DA344 <108473820+DA-344@users.noreply.github.com>
Date: Wed, 3 Jan 2024 19:31:30 +0100
Subject: [PATCH 1/4] Update playing.mdx to show the newest version of Wavelink
Updated the code snippets so it shows how it must be done in the latest wavelink version
Signed-off-by: DA344 <108473820+DA-344@users.noreply.github.com>
---
docs/voice/playing.mdx | 64 +++++++++++++++++++++++++++---------------
1 file changed, 41 insertions(+), 23 deletions(-)
diff --git a/docs/voice/playing.mdx b/docs/voice/playing.mdx
index ad764b9a..72c3a6ac 100644
--- a/docs/voice/playing.mdx
+++ b/docs/voice/playing.mdx
@@ -47,12 +47,15 @@ async def connect_nodes():
"""Connect to our Lavalink nodes."""
await bot.wait_until_ready() # wait until the bot is ready
- await wavelink.NodePool.create_node(
- bot=bot,
- host='0.0.0.0',
- port=2333,
- password='youshallnotpass'
- ) # create a node
+ nodes = [
+ wavelink.Node(
+ identifier="Node1", # This identifier must be unique for all the nodes you are going to use
+ uri="http://0.0.0.0:443", # Protocol (http/s) is required, por must be 443 as it is the one lavalink uses
+ password="youshallnotpass"
+ )
+ ]
+
+ await wavelink.Pool.connect(nodes=nodes, client=bot) # Connect our nodes
```
@@ -67,23 +70,35 @@ Now you are finished making your node! Next, you will want to:
To make a play command, you will need to make a function to connect and play audio in a voice channel.
```py title="Play Command Example"
+import typing
+
@bot.slash_command(name="play")
async def play(ctx, search: str):
- vc = ctx.voice_client # define our voice client
-
- if not vc: # check if the bot is not in a voice channel
- vc = await ctx.author.voice.channel.connect(cls=wavelink.Player) # connect to the voice channel
-
- if ctx.author.voice.channel.id != vc.channel.id: # check if the bot is not in the voice channel
- return await ctx.respond("You must be in the same voice channel as the bot.") # return an error message
-
- song = await wavelink.YouTubeTrack.search(query=search, return_first=True) # search for the song
-
- if not song: # check if the song is not found
- return await ctx.respond("No song found.") # return an error message
-
- await vc.play(song) # play the song
- await ctx.respond(f"Now playing: `{vc.source.title}`") # return a message
+ # First we may define our voice client,
+ # for this, we are going to use typing.cast()
+ # function just for the type checker know that
+ # `ctx.voice_client` is going to be from type
+ # `wavelink.Player`
+ vc = typing.cast(wavelink.Player, ctx.voice_client)
+
+ if not vc: # We firstly check if there is a voice client
+ vc = await ctx.author.voice.channel.connect(cls=wavelink.Player) # If there isn't, we connect it to the channel
+
+ # Now we are going to check if the invoker of the command
+ # is the same voice channel than the voice client, when defined.
+ # If not, we return an error message.
+ if ctx.author.voice.channel.id != vc.channel.id:
+ return await ctx.respond("You must be in the same voice channel as the bot.")
+
+ # Now we search for the song. You can optionally
+ # pass the "source" keyword, from type "wavelink.TrackSource"
+ song = await wavelink.Playable.search(search)
+
+ if not song: # In case the song is not found
+ return await ctx.respond("No song found.") # we return an error message
+
+ await vc.play(song) # Else, we play it
+ await ctx.respond(f"Now playing: `{vc.source.title}`") # and return a success message
```
@@ -113,8 +128,11 @@ async def on_ready():
await connect_nodes() # connect to the server
@bot.event
-async def on_wavelink_node_ready(node: wavelink.Node):
- print(f"{node.identifier} is ready.") # print a message
+async def on_wavelink_node_ready(payload: wavelink.NodeReadyEventPayload):
+ # Everytime a node is successfully connected, we
+ # will print a message letting it know.
+ print(f"Node with ID {payload.session_id} has connected")
+ print(f"Resumed session: {payload.resumed}")
bot.run("token")
```
From 7d56439925397a1c0b3068fe6593497d5063e284 Mon Sep 17 00:00:00 2001
From: DA344 <108473820+DA-344@users.noreply.github.com>
Date: Wed, 3 Jan 2024 19:34:28 +0100
Subject: [PATCH 2/4] Update a bit the code comments
Signed-off-by: DA344 <108473820+DA-344@users.noreply.github.com>
---
docs/voice/playing.mdx | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/docs/voice/playing.mdx b/docs/voice/playing.mdx
index 72c3a6ac..d4d95ce6 100644
--- a/docs/voice/playing.mdx
+++ b/docs/voice/playing.mdx
@@ -85,13 +85,13 @@ async def play(ctx, search: str):
vc = await ctx.author.voice.channel.connect(cls=wavelink.Player) # If there isn't, we connect it to the channel
# Now we are going to check if the invoker of the command
- # is the same voice channel than the voice client, when defined.
+ # is in the same voice channel than the voice client, when defined.
# If not, we return an error message.
if ctx.author.voice.channel.id != vc.channel.id:
return await ctx.respond("You must be in the same voice channel as the bot.")
# Now we search for the song. You can optionally
- # pass the "source" keyword, from type "wavelink.TrackSource"
+ # pass the "source" keyword, of type "wavelink.TrackSource"
song = await wavelink.Playable.search(search)
if not song: # In case the song is not found
From 3b63c3ef6aac19fd6f43687debe8058ef56060e0 Mon Sep 17 00:00:00 2001
From: DA344 <108473820+DA-344@users.noreply.github.com>
Date: Wed, 3 Jan 2024 19:37:13 +0100
Subject: [PATCH 3/4] Minor typo
Signed-off-by: DA344 <108473820+DA-344@users.noreply.github.com>
---
docs/voice/playing.mdx | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/voice/playing.mdx b/docs/voice/playing.mdx
index d4d95ce6..541bf77a 100644
--- a/docs/voice/playing.mdx
+++ b/docs/voice/playing.mdx
@@ -50,7 +50,7 @@ async def connect_nodes():
nodes = [
wavelink.Node(
identifier="Node1", # This identifier must be unique for all the nodes you are going to use
- uri="http://0.0.0.0:443", # Protocol (http/s) is required, por must be 443 as it is the one lavalink uses
+ uri="http://0.0.0.0:443", # Protocol (http/s) is required, port must be 443 as it is the one lavalink uses
password="youshallnotpass"
)
]
From 678457aafe748e98e9e06e3a3c49daa898b2d5b5 Mon Sep 17 00:00:00 2001
From: DA344 <108473820+DA-344@users.noreply.github.com>
Date: Wed, 3 Jan 2024 19:41:16 +0100
Subject: [PATCH 4/4] Change "vc.source.title" to "song.title"
Signed-off-by: DA344 <108473820+DA-344@users.noreply.github.com>
---
docs/voice/playing.mdx | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/voice/playing.mdx b/docs/voice/playing.mdx
index 541bf77a..1f1f3c76 100644
--- a/docs/voice/playing.mdx
+++ b/docs/voice/playing.mdx
@@ -98,7 +98,7 @@ async def play(ctx, search: str):
return await ctx.respond("No song found.") # we return an error message
await vc.play(song) # Else, we play it
- await ctx.respond(f"Now playing: `{vc.source.title}`") # and return a success message
+ await ctx.respond(f"Now playing: `{song.title}`") # and return a success message
```