【发布时间】:2021-09-30 00:58:50
【问题描述】:
我正在创建一个简单的音乐机器人,但我无法弄清楚为什么机器人没有音频。我试过踢和重新加入,更改代码等等。我就是想不通。命令行没有错误,机器人周围有一个绿色的小圆圈,就好像它有音频一样。但是,如果您重新加入 VC,它就会消失。
代码如下:
import discord
from discord.utils import get
from discord.ext import commands
from discord import FFmpegPCMAudio
from discord.voice_client import VoiceClient
import youtube_dl
import os
TOKEN = "Token Here"
bot = commands.Bot(command_prefix='s')
intents = discord.Intents.default()
intents.members = True
client = commands.Bot(command_prefix=',', intents = intents)
@bot.event
async def on_ready():
channel = discord.utils.get(bot.get_all_channels(), id=794444804607574026)
await channel.connect()
@bot.command(name='play')
async def play(ctx, url):
await message.content.startswith('play')
player = await voice_client.create_ytdl_player(url)
player = await voice.create_ytdl_player("https://youtu.be/K4DyBUG242c")
player = await vc.create_ytdl_player()
player.start()
bot.run(TOKEN)
如果您愿意,请随时改进它。我从 YouTube 教程中获得了这段代码,所以我不完全理解音频部分。
【问题讨论】:
-
await message.content.startswith('play')这一行是什么意思?首先你没有定义message,其次你为什么要等它? -
您使用的是过时的方法。如果你看教程,请看最近的,因为
discord.py经常更新。例如,您可以查看this answer
标签: python ffmpeg discord.py