提问人:MrGr1zz62 提问时间:11/16/2023 最后编辑:MrGr1zz62 更新时间:11/16/2023 访问量:24
Discord 机器人可以加入语音频道,但不会发出声音 (discord.py)
Discord bot can join voice channels but doesn't make sounds (discord.py)
问:
我正在为我的服务器编写一个机器人,并决定添加一个音乐系统。由于 youtube-dl 被阻止,我决定使用 wavelink。我对它了解不多,因此可能会在代码中犯错误,但仍然涉及主题。在控制台中没有错误,机器人在进入命令播放时看到请求并可以进入语音通道,但没有任何打开,通常在它附近不会出现绿色圆圈。请帮忙。
import discord
import wavelink
from discord.ext import commands
class Bot(commands.Bot):
def __init__(self) -> None:
intents = discord.Intents(messages=True, guilds=True, reactions=True, members=True, presences=True)
intents.message_content = True
super().__init__(intents=intents, command_prefix='!')
async def on_ready(self) -> None:
print(f'Logged in {self.user} | {self.user.id}')
async def setup_hook(self) -> None:
# Wavelink 2.0 has made connecting Nodes easier... Simply create each Node
# and pass it to NodePool.connect with the client/bot.
node: wavelink.Node = wavelink.Node(uri='https://lava1.horizxon.tech:443', password='horizxon.tech', secure=True)
await wavelink.NodePool.connect(client=self, nodes=[node])
bot = Bot()
levels = {}
@bot.command()
async def play(ctx: commands.Context, *, search: str) -> None:
"""Простая команда воспроизведения."""
if not ctx.voice_client:
vc: wavelink.Player = await ctx.author.voice.channel.connect(cls=wavelink.Player)
else:
vc: wavelink.Player = ctx.voice_client
tracks = await wavelink.YouTubeTrack.search(search)
if not tracks:
await ctx.send(f'Сори броу, я не нашёл этого трека: `{search}`')
return
track = tracks[0]
await vc.play(track)
await ctx.send(f"Сейчас играет: ***{track}***")
@bot.command()
async def stop(ctx: commands.Context) -> None:
"""Simple disconnect command.
This command assumes there is a currently connected Player.
"""
vc: wavelink.Player = ctx.voice_client
await vc.disconnect()
await ctx.send(f"стоп")
我尝试更改代码并基于 FFmpeg 制作新代码来测试机器人中的声音,但是机器人在加入命令时加入和退出时没有发出任何声音
答: 暂无答案
评论
wavelink