Skip to content

Commit

Permalink
fix guide
Browse files Browse the repository at this point in the history
  • Loading branch information
Lulalaby committed Apr 18, 2024
1 parent 541786e commit c87ec60
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 24 deletions.
2 changes: 1 addition & 1 deletion docs/interactions/ui-components/dropdowns.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class MyView(discord.ui.View):

@bot.command()
async def flavor(ctx):
await ctx.send("Choose a flavor!", view=MyView())
await ctx.respond("Choose a flavor!", view=MyView())

bot.run("TOKEN")
```
Expand Down
1 change: 1 addition & 0 deletions docs/more/community-resources.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ This page showcases the amazing things created by the Pycord community, includin

| Name | Type | Link |
| ------------------------ | ------------ | ----------------------------------------------------------------------------------- |
| CookieBot | Multipurpose | [website](https://cookie-bot.xyz) |
| Discord-Multipurpose-Bot | Multipurpose | [github](https://github.com/pogrammar/Discord-multipurpose-bot/tree/master/Python) |
| _GZ_ Global | Chatting | [website](https://www.gzglobal.eu/) |
| inconnu | Fun & QOL | [github](https://github.com/tiltowait/inconnu) |
Expand Down
64 changes: 41 additions & 23 deletions docs/voice/playing.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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, port must be 443 as it is the one lavalink uses
password="youshallnotpass"
)
]

await wavelink.Pool.connect(nodes=nodes, client=bot) # Connect our nodes
```

<br />
Expand All @@ -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 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, of 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: `{song.title}`") # and return a success message
```

<DiscordComponent>
Expand Down Expand Up @@ -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")
```
Expand Down

0 comments on commit c87ec60

Please sign in to comment.