Discord: Slash Commands In 8 Minutes (Python)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
you're right there guys so today i'm going to be going over the new discord slash commands as quickly and most importantly helpful as possible i'll be using python 3.8 for this video so let's go ahead and get started first we're going to go to google and we're gonna type discord slash commands pip we'll go to the top link we're gonna copy this command and then we'll open up terminal and we'll paste that in there and press enter next we're going to go back to google we're going to type in discord portal i'm going to click the top link go to applications new application and then i'm just going to give this a name dev spot click create next we're going to go to bot and then click add bot and then yes do it next let's go to auth 2 we'll scroll down a little bit i'm going to select bot and then applications command we're also going to uh select administrator here and copy that link and we're going to paste that in a new tab and we want to select our server continue and then authorize and then just do the capture and as you can see the bot is now in our server so now we're going to create a file called main.pi i'm going to import discord from discord import commands then from discord underscore slash we're going to import slash command and then slash context next uh from discord underscore slash dot utils dot manage command we're going to import create choice and then create option so now let's go ahead and create the client so client is equal to commands dot bot i'm going to set a command prefix here i'm going to set that to exclamation you can do whatever you want let's create a variable called slash and that's slash command and then we need to pass in the client and then we need to make sure sync commands is equal to true now we're going to go ahead and create the slash command and all we've got to do is uh type at slash dot slash and then we're going to provide a name it's going to be hello and then we can also provide a description here and i'm just going to say just sends a message then async def hello and then we're going to pass in a context which is the slash context and then we're just going to await ctx dot send and then will we also need to pass in uh guild ids so guild underscore ids is equal to and then let's go back to discord and we're going to right click and then copy id on the server and then in a list we're just going to paste it in there like so you may be wondering what this guild id is um so basically all you've got to remember is uh you need to get the id for each server the bot is in so that's all that matters just remember that next we need to run the bot so we're going to type client.run and then we're going to pass in token we've not created this yet so let's go back to our web browser let's go to the developer portal we're going to go back to bot we'll scroll up and then we're going to copy this token and then at the top we're going to create a variable called token and then we're just going to paste that in there i have made a little letter up here this has got to be discord.ext so let's open up a new terminal i'm going to type python3 main.pi and press enter let's go back to discord and you can see that the bot is now online so now we can go ahead and run that command by typing slash hello we'll press enter and you can see world perfect so now let's create some options to choose from so we're going to type options and that's going to be a list i'm going to type create option we're going to pass in a name i'm going to set this to option and then we can also pass in a description which is just i don't know choose your word we can also set required to true or false and we're going to set the option type to six i'll explain a little bit more about this later on so now we're going to um we're going to create some choices so we're going to type choices that's going to be a list and then create choice and then we'll pass in a name i'm just going to type world and then a value which is just world and then same again for you so create choice name equal to you and then value is equal to u i've just realized a minute error here this needs to be 3 and then we'll scroll down and then we're going to pass in option and that's going to be a string we'll replace world with option and we need to restart our bot let's go back to discord and we're going to type slash hello and then we've got options i'm going to select you press enter and you can see you and then we'll do the same for world perfect let's go to uh google i'm going to type discord slash commands and we're going to go to the official documentation go to get started and scroll down a little bit and you can see these are the option types that we can provide we was using a string next we're going to use a user so let's do that right now so now we need to get the user id but we need to do some changes i'm going to change name to get user i'm going to replace the description now uh we'll set the description for uh create option select a user then we're gonna get rid of these choices and set the option type to six and i'm replacing the uh command name get user i'm going to change option uh we need to set the name to user then pass in user and then the user dot id let's restart the bot let's go back to discord and we're going to type slash get user and then we'll select a user press enter and then we've got the id so this was a quick introduction for slash commands in discord if you want to check out more you can visit the link in the description below for the official documentation please subscribe if you haven't already we're close to a thousand subscribers so it'll be awesome if we can reach that so again thanks watching and i will see you in the next one
Info
Channel: DEVSPOT
Views: 10,619
Rating: undefined out of 5
Keywords:
Id: ygc-HdZHO5A
Channel Id: undefined
Length: 7min 52sec (472 seconds)
Published: Fri May 28 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.