gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 23:01:25 26 4
gpt4 key购买 nike

我正在创建一个简单的音乐机器人,但我无法弄清楚为什么机器人没有音频。我试过踢和重新加入,更改代码等等。我就是想不通。命令行没有错误,机器人周围有一个绿色的小圆圈,就好像它有音频一样。但是,如果您重新加入 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 开头, 机器人前缀是 "," .
另外,您添加 intentsclient .您应该将其设置为 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)

关于python - 没有来自不和谐机器人的音频。不和谐.py/ffmpeg,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68490024/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com