【发布时间】:2019-05-05 08:55:37
【问题描述】:
我是 Python 的初学者,最近开始为我和一些朋友制作一个不和谐的机器人。我的想法是输入 !startq 并让机器人加入频道,播放本地存储在bot.py 也在同一个文件夹中。
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')
到目前为止,我的机器人可以正常加入频道,但它实际上并没有播放 mp3。我在“Unofficial Discord API Discord”和其他一些编程 Discords 中问过无数人,但我还没有得到答案。
【问题讨论】:
-
bot.run应该在您的功能之外。请参阅the documentation中的示例 -
是的,我只是将它添加到此线程错误。对不起!
-
你安装了FFmpeg吗?
-
是的,我确实 pip install ffmpeg 并且它安装正确。虽然仍然无法让它工作
-
需要单独下载FFmpeg 可以在这里找到:ffmpeg.org。下载后,请确保将exe添加到您的路径环境变量中,否则将无法正常工作。见这里:discordpy.readthedocs.io/en/rewrite/…
标签: python-3.x ffmpeg discord discord.py