(Input the token which you copied earlier here) Running the Discord Bot and Playing YouTube Audio Īt last to connect the bot to server we call the n()method with bot’s token as parameter. The second event handler, on_message() is triggered when a message is sent in any channel that the bot has access to.In this case,it check if the message content is equal to “!hello” if so the bot sends message back to the same channel and greet the user who send it. Then we define two handlers the first one being on_read() which is triggered when the bot has successfully connected to discord and is ready to receive events.It prints a message to console to alert that the bot has logged in and its user ID. We set mbers to True as to enable members intent since its disable by default. ![]() Intents enable the bot to receive certain events such as on_member_join and on_member_remove events. This code imports the discord module we then create a Client instance with the intents enabled. After the bot is connected to server you can find the bot at left side bar. Visual representation of above stepsĭo not forget to reset the token and copy it somewhere as we will be using it later. To connect the bot we paste the above URL in the browser where we open our discord and select the serverīelow is a video of the entire steps mentioned above. Use generated URL to connect the bot to your server Scroll down to select permissions Connect and Speak Save changes, reset the bot token, and copy it (for use in Python code)Īdd bot to server by going to OAuth2 tab, selecting “bot” under scope, and choosing “Connect” and “Speak” permissions SPEAK: This permission allows your bot to speak in a voice channel. Navigate to the “Bot” tab, click “Add Bot,” and create a Bot UserĮnable desired Privileged Gateway Intents, such as SERVER MEMBERS INTENT and MESSAGE CONTENT INTENTĬONNECT: This permission allows your bot to connect to a voice channel. Click on “New Application,” give it a name, and click “Create”. ![]() Setting up Your Discord Bot and Connecting to a ServerĬreate a new Discord bot application and connect it to a server Run the code, and then input “!play youtube_URL” in the text channel to have the bot play the audio. Set up Privileged Gateway Intents, add “Connect” and “Speak” permissions, and use the bot’s token within the Python code. ![]() To make your Discord bot play YouTube audio, create a new Discord bot application, connect it to your server, and write Python code using the discord module to handle events. Let us make our discord bot play audio from YouTube. It allows users to create and join servers, like virtual meeting places where people can chat, voice call, and share media with one another. Discord is a popular communication platform initially developed for gamers but now other communities use it too.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |