How To Code a Discord Music Bot
Why Stack Overflow recommends it
Stack Overflow users cite it as the tutorial they followed when asking why their discord.py music bot throws errors such as CommandNotFound, a missing voice client, or add_cog failures.
Recommended by 4 people across 4 different months, 2021 to 2022.
What it is
A short tutorial by Max Codez on building a simple Discord music bot in Python with discord.py and youtube_dl, a budget take on the Rythm bot. It covers cogs, joining and leaving voice channels, and playing YouTube audio.
What people said
Recommends Slopolot · 2021-09 · Stack Overflow · on “My Discord python music bot gets an error when asked to play”
I would appreciate the help in narrowing down this issue. My Discord Bot will run in my python environment without errors initially. However, when I try and enter a command to stream a song from youtube, I'll get the below error: Traceback (most recent call last): File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 85, in wrapped ret = await coro(*args, **kwargs) File "/home/runner/DiscordMusicBot/music.py", line 25, in play ctx.voice_client.stop() AttributeError: 'NoneType' object has no attribute 'stop' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/opt/virtualenvs/python3/lib/python3
Recommends Gollum · 2021-12 · Stack Overflow · on “Python Discord Bot isn't joinig voice channel”
import discord from discord.ext import commands client = discord.Client() bot = commands.Bot(command_prefix="!") @client.event async def on_ready(): print("I'm logged in as {0.user}.".format(client)) @client.event async def on_message(message): if message.author == client.user: return if message.content.startswith("!test"): await message.channel.send("Test passed successfully!") @commands.command() async def join(self,ctx): if ctx.author.voice is None: await ctx.send("You are not in a voice channel") voice_channel = client.get_channel(ctx.author.voice.channel.id) if ctx.voice_client is None: await voice_channel.connect() else: await ctx.voice_client.move_to(voice_channel) await ctx.send("idk
Recommends monsnoor89 · 2022-03 · Stack Overflow · on “AttributeError: 'tuple' object has no attribute 'add_cog'”
I'm trying to make a discord music bot, but I'm getting this error: Traceback (most recent call last): File "main.py", line 11, in <module> cogs[i].setup(client) File "/home/runner/MOMOSNACK-BOT/music.py", line 48, in setup client.add_cog(music(client)) AttributeError: 'tuple' object has no attribute 'add_cog'` I am following this tutorial: [this video] I have tried replacing client.add_cog(music(client)) with: client.add.cog(music(client)) bot.add_cog(music(client)) bot.add_cog(music(bot)) Along with all the variations of capitalization, but none of these seemed to have fixed my problem. Thanks in advance for any help! This is my music.py : import discord from discord.ext import commands import
Recommends lad12345 · 2022-09 · Stack Overflow · on “Why am I getting the error "command is not found"?”
I was following this tutorial [this video] on how to create a discord music bot like Rythm using discord.py. I had troubleshooted my code and fixed a few errors to do with coroutine. I have called the r function and now get this error upon running the code: main.py:15: RuntimeWarning: coroutine 'r' was never awaited r() When I run the code everything boots up successfully until I try to use a command. If I put '@join' in the chat it should have joined the voice chat or said "You're not in a voice channel!". Instead I get this error: 2022-09-02 20:07:08 ERROR discord.ext.commands.bot Ignoring exception in command None discord.ext.commands.errors.CommandNotFound: Command "join" is not found I have
Cites joeeyh · 2021-09 · Stack Overflow · on “How do I add a search funtion to my discord music bot?”
I would like to add a search function to my discord music bot however my little knowledge in pyhton is hindering me frm doing so. I would like to make is so that whenever someone puts in chat: ?search (song name) it would play the song in the voice channel. I have watched this video here [this video] and added some of my own little tweaks, however that is all. I have tried looking at other stack overflow pages but io dont know how to tweak their code to work with mine, any help? Ty Code: import discord from discord.ext import commands import youtube_dl from requests import get from youtube_dl import YoutubeDL class music(commands.Cog): def __init__(self,client): self.client = client @commands.com
Cites Prab-mat · 2021-09 · Stack Overflow · on “Writing down TokenID for the discord bot prompts a Runtime error”
import discord from discord.ext import commands import music cogs = [music] client = commands.Bot(command_prefix='-', intents = discord.Intents.all()) for i in range(len(cogs)): cogs[i].setup(client) client.run('TOKEN') ________Music.py________ import discord from discord.ext import commands import youtube_dl class music(commands.Cog): def __init__(self, client): self.client = client @commands.command() async def join(self,ctx): if ctx.author.voice is None: await ctx.send("You are not in a voice channel!") voice_channel = ctx.author.voice.channel if ctx.voice_client is None: await voice_channel.connect() else: await ctx.voice_client.move_to(voice_channel) @commands.command() async def discon
Cites RoySykes · 2022-11 · Stack Overflow · on “ERROR discord.ext.commands.bot Ignoring exception in command None discord.ext.commands.errors.CommandNotFound: Command "join" is not found”
i been trying to make a music bot to get some practice in python so i follow this video: [this video] and the code gives me this error: ERROR discord.ext.commands.bot Ignoring exception in command None discord.ext.commands.errors.CommandNotFound: Command "join" is not found PS D:\PROGRAMACION\DiscordBot> & 'C:\Users\roysy\AppData\Local\Microsoft\WindowsApps\python3.10.exe' 'c:\Users\roysy\.vscode\extensions\ms-python.python-2022.18.2\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher' '63393' '--' 'd:\PROGRAMACION\DiscordBot\roydiscordbot.py' d:\PROGRAMACION\DiscordBot\roydiscordbot.py:10: RuntimeWarning: coroutine 'setup' was never awaited cogs[i].setup(client) RuntimeWarning: Enable