没有来自 discord 机器人的音频。不和谐py/ffmpeg

No audio from discord bot. discord.py/ffmpeg

我正在创建一个简单的音乐机器人,但我不明白为什么机器人没有音频。我试过踢和重新加入、更改代码等等。我就是想不通。命令行没有错误,机器人周围有一个绿色的小圆圈,就好像它有音频一样。但是,如果您重新加入 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 教程中获得这段代码,所以我不完全理解音频部分。

试试这个。当您 运行 命令消息永远不会以 play 开头时,bot 前缀是 ",".

此外,您将 intents 添加到 client。您应该将其设置为 bot 并删除 client,您永远不要在代码中使用它。

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"

intents = discord.Intents.default()
intents.members = True
bot = 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)