From 81c2b330983bc27783a0e1d946351f477deb487a Mon Sep 17 00:00:00 2001 From: Lala Sabathil Date: Thu, 18 Apr 2024 13:18:49 +0200 Subject: [PATCH] fix guide --- .github/workflows/codespell.yml | 2 +- .github/workflows/deploy.yml | 2 +- .github/workflows/devskim.yml | 2 +- .github/workflows/node.js.yml | 4 +- .github/workflows/test-deploy.yml | 2 +- docs/interactions/ui-components/dropdowns.mdx | 2 +- docs/more/community-resources.mdx | 1 + docs/voice/playing.mdx | 64 ++++++++++++------- package.json | 2 +- yarn.lock | 5 +- 10 files changed, 52 insertions(+), 34 deletions(-) diff --git a/.github/workflows/codespell.yml b/.github/workflows/codespell.yml index 2079c87b..1a34d1df 100644 --- a/.github/workflows/codespell.yml +++ b/.github/workflows/codespell.yml @@ -10,4 +10,4 @@ jobs: with: python-version: "3.x" - run: pip install codespell - - run: codespell --ignore-words-list="groupt,nd,ot,claus" --skip="./yarn.lock" + - run: codespell --ignore-words-list="groupt,nd,ot,claus,everytime" --skip="./yarn.lock" diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 9b55a2d6..cb979213 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: actions/setup-node@v3 + - uses: actions/setup-node@v4 with: node-version: 18 cache: yarn diff --git a/.github/workflows/devskim.yml b/.github/workflows/devskim.yml index 6d5b2400..b95b5854 100644 --- a/.github/workflows/devskim.yml +++ b/.github/workflows/devskim.yml @@ -16,7 +16,7 @@ on: jobs: lint: name: DevSkim - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest permissions: actions: read contents: read diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index fcce0c7b..7d73ce81 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -12,13 +12,13 @@ jobs: strategy: matrix: - node-version: [16.14] + node-version: [18] # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ steps: - uses: actions/checkout@v4 - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} cache: 'yarn' diff --git a/.github/workflows/test-deploy.yml b/.github/workflows/test-deploy.yml index dce6f050..3b506d6d 100644 --- a/.github/workflows/test-deploy.yml +++ b/.github/workflows/test-deploy.yml @@ -16,7 +16,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: actions/setup-node@v3 + - uses: actions/setup-node@v4 with: node-version: 18 cache: yarn diff --git a/docs/interactions/ui-components/dropdowns.mdx b/docs/interactions/ui-components/dropdowns.mdx index 081cfad7..a0f19579 100644 --- a/docs/interactions/ui-components/dropdowns.mdx +++ b/docs/interactions/ui-components/dropdowns.mdx @@ -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") ``` diff --git a/docs/more/community-resources.mdx b/docs/more/community-resources.mdx index bd7239dd..8c7a35e7 100644 --- a/docs/more/community-resources.mdx +++ b/docs/more/community-resources.mdx @@ -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) | diff --git a/docs/voice/playing.mdx b/docs/voice/playing.mdx index ad764b9a..1f1f3c76 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, port 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 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 ``` @@ -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") ``` diff --git a/package.json b/package.json index 48e788f6..9e9ce1c0 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "@mdx-js/react": "1.6.22", "@types/react": "17.0.2", "clsx": "2.0.0", - "discord-message-components": "https://gitpkg.now.sh/Pycord-Development/discord-message-components?aa468ada9b2b52986ae0aee4051660713c1e9095&scripts.postinstall=yarn%20install%20--ignore-scripts%20%26%26%20node%20node_modules%2Fesbuild%2Finstall.js%20%26%26yarn%20build%3Amarkdown%20%26%26%20yarn%20build%3Acore%20%26%26%20yarn%20build%3Areact", + "discord-message-components": "https://gitpkg.now.sh/Pycord-Development/discord-message-components?aa468ada9b2b52986ae0aee4051660713c1e9095&scripts.postinstall=yarn%20install%20--ignore-scripts%20%26%26%20node%20node_modules%2Fesbuild%2Finstall.js%20%26%26yarn%20build%3Amarkdown%20%26%26%20yarn%20build%3Acore%20%26%26%20yarn%20build%3Areact%20%26%26", "docusaurus-plugin-sass": "0.2.5", "prism-react-renderer": "1.3.5", "react": "17.0.2", diff --git a/yarn.lock b/yarn.lock index d16ab765..0f30cf5a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1434,7 +1434,6 @@ "@discordapp/twemoji@discord/twemoji": version "14.1.2" - uid c9fb242544b5f9068221d3baadb3b5d7ec9727c0 resolved "https://codeload.github.com/discord/twemoji/tar.gz/c9fb242544b5f9068221d3baadb3b5d7ec9727c0" dependencies: fs-extra "^8.0.1" @@ -3985,9 +3984,9 @@ dir-glob@^3.0.1: dependencies: path-type "^4.0.0" -"discord-message-components@https://gitpkg.now.sh/Pycord-Development/discord-message-components?aa468ada9b2b52986ae0aee4051660713c1e9095&scripts.postinstall=yarn%20install%20--ignore-scripts%20%26%26%20node%20node_modules%2Fesbuild%2Finstall.js%20%26%26yarn%20build%3Amarkdown%20%26%26%20yarn%20build%3Acore%20%26%26%20yarn%20build%3Areact": +"discord-message-components@https://gitpkg.now.sh/Pycord-Development/discord-message-components?aa468ada9b2b52986ae0aee4051660713c1e9095&scripts.postinstall=yarn%20install%20--ignore-scripts%20%26%26%20node%20node_modules%2Fesbuild%2Finstall.js%20%26%26yarn%20build%3Amarkdown%20%26%26%20yarn%20build%3Acore%20%26%26%20yarn%20build%3Areact%20%26%26": version "0.0.0" - resolved "https://gitpkg.now.sh/Pycord-Development/discord-message-components?aa468ada9b2b52986ae0aee4051660713c1e9095&scripts.postinstall=yarn%20install%20--ignore-scripts%20%26%26%20node%20node_modules%2Fesbuild%2Finstall.js%20%26%26yarn%20build%3Amarkdown%20%26%26%20yarn%20build%3Acore%20%26%26%20yarn%20build%3Areact#d91f955d42a5d27381cb4af5d7d6c290122ad45f" + resolved "https://gitpkg.now.sh/Pycord-Development/discord-message-components?aa468ada9b2b52986ae0aee4051660713c1e9095&scripts.postinstall=yarn%20install%20--ignore-scripts%20%26%26%20node%20node_modules%2Fesbuild%2Finstall.js%20%26%26yarn%20build%3Amarkdown%20%26%26%20yarn%20build%3Acore%20%26%26%20yarn%20build%3Areact%20%26%26#b9976a195da1dfaf42fffe712a0ca743076971f3" dns-equal@^1.0.0: version "1.0.0"