My space to

flarecoat0's blog

header photo

blog post

Make discord bot to assign roles with Python (Part 7: track Bot) | most up-to-date Discord Py Version
hiya everyone welcome back it's been a. while since i uploaded my final video. and that i express regret for that but happily. i am again. today i've one other tremendously asked. discord pie. academic during this video we are going to. be creating a simple song. bot i'm going to go over how to hitch and. depart voice channels as well as . play pause and resume audio there are. going to be some requirements for this. assignment. including ffmpeg and youtube dl. which we're both going to put in in. this educational i am going to assist you do. that later. yet for now let's leap right into the. code and get into pycharm. here in pycharm i have my uncomplicated template. mounted. if you have never coded a discord bot. earlier than i tremendously mean you investigate my. previous discord pie movies where i show. you. step by step the way to get everything set. up. and people will be linked in the.
Description. so the first command ii'm going to create. is the play command. and i'm unlikely to precisely total. this play command. simply yet i will first write a. little bit of code in it and then. we are going to write the extra tricky code. when we're comprehensive with all the other. instructions. so we're going to say at client.command. and then we're going to create a. an asynchronous function we'll. call this play. and we're going to pass in ctx we're. additionally going to pass in. a parameter known as url and we are going. to make sure that this url. is determined to a string so whilst the user. calls this command they're truly. going to. replica and paste a url into it and that. will be. the audio source that plays. the subsequent factor we want to do is get the. voice channel we want to. connect our bot to so we are going to say voice. channel equals discord.utils.get.
The discord.utils library is a great way. to. acquire data and entry the. channels and servers that your bot is in. so basically what we will do. with it's search for. the voice channel with the particular call. so we are going to say ctx dot guild dot. voice underscore channels. then a comma and we are going to placed name. equals trendy. so in the server i have hooked up for this. project. i only have one voice channel and it's. referred to as popular but. in all probability your voice channel is going. to be named something distinctive so. you're just going to wish to alter that. right here. and if you don't always desire to. have it simply be one voice channel that. your bot connects to. one could circulate in an extra. argument in the command so we are going to say. channel. and then you'll change this to. channel so the user might. even have to provide the channel name when.
They known as the command. but for my purposes i am just going to. go away this as. trendy and take away this parameter here. once we've the channel we want to. access we need to hooked up a voice client. so we'll create yet another. variable referred to as voice and we are going to say. voice equals discord.utils.get. and this time we will do purchaser. and then dot voice customers so that's. going to look via all the voice. customers. and we'll set the guild equivalent to ctx. dot guild so this is going to go through. all of the voice clients. within the guild and choose one to use. a voice client just aallows us to use. the various capabilities. that the discord pi library gives us. with. voice channels now to get our bot to. correctly join the voice. channel we are able to use this command called. anticipate voice channel. dot connect. and if we run this code so i'll.

Run this. and our bot is on line

Go Back

Comment