I'm a beginner in Python and I have recently started making a discord bot for some friends and I. The idea is to type !startq and have the bot join the channel, play an mp3 file that is locally stored in the same folder that the bot.py is in also.
import discord, chalk
from discord.ext import commands
import time
import asyncio
bot = commands.Bot(command_prefix = "!")
@bot.event
async def on_ready():
print("Bot is ready!")
@bot.command()
async def q5(ctx):
await ctx.send("@here QUEUE STARTING IN 5 MINUTES")
@bot.command()
async def q3(ctx):
await ctx.send("@here QUEUE STARTING IN 3 MINUTES")
@bot.command()
async def q1(ctx):
await ctx.send("@here QUEUE STARTING IN 1 MINUTES")
@bot.command()
async def ping(ctx):
ping_ = bot.latency
ping = round(ping_ * 1000)
await ctx.send(f"my ping is {ping}ms")
@bot.command()
async def startq(ctx):
voicechannel = discord.utils.get(ctx.guild.channels, name='queue')
vc = await voicechannel.connect()
vc.play(discord.FFmpegPCMAudio("countdown.mp3"), after=lambda e: print('done', e))
bot.run('TOKEN')
So far my bot joins the channel fine, but it doesn't actually play the mp3. I've asked countless people in the "Unofficial Discord API Discord" and a few other programming Discords, but I haven't gotten an answer yet.
bot.run
should be outside of your function. See the examples in the documentation – Patrick Haugh