提问人:Domi 提问时间:11/16/2023 最后编辑:Domi 更新时间:11/16/2023 访问量:20
Lavalink discord 音乐机器人无法连接到语音频道
Lavalink discord music bot doesn't connect to voice channel
问:
**机器人只是写道它无法连接到语音通道,我已经尝试制作一个机器人大约一个月了,但总是出现某种错误,然后它会连接和音乐等等......我累了 **
import nextcord
from nextcord.ext import commands
from nextcord.shard import EventItem
import wavelinkcord
import wavelinkcord as wavelink
import logging
logging.basicConfig(level=logging.INFO)
bot_version = "0.0.1"
intents = nextcord.Intents.all()
client = nextcord.Client()
bot = commands.Bot(command_prefix="%", intents=intents)
@bot.event
async def on_ready():
print("Bot Ready!")
bot.loop.create_task(on_node())
async def on_node():
node: wavelink.Node = wavelink.Node(uri="http://lavalink.clxud.dev:2333", password="youshallnotpass")
await wavelink.NodePool.connect(client=bot, nodes=[node])
wavelink.Player.autoplay = True
@bot.command(guild_ids=[])
async def play(interaction: nextcord.Interaction, search: str):
query = await wavelink.YouTubeTrack.search(search)
if query:
track = query[0]
# Получаем пользователя, который вызвал команду
user = interaction.author
# Проверяем, находится ли пользователь в голосовом канале
if user.voice and user.voice.channel:
destination = user.voice.channel
if interaction.guild.voice_client:
vc: wavelink.Player = destination.connect(cls=wavelink.Player)
else:
vc: wavelink.Player = bot.get_guild(interaction.guild.id).voice_client
# Проверяем, существует ли объект vc
if vc:
print(f"Connected to voice channel: {destination}")
if vc.query.is_empty and not vc.is_playing():
await vc.play(track)
else:
await vc.queue.put_wait(track)
else:
print("Failed to connect to voice channel.")
await interaction.send(f"Не удалось подключиться к голосовому каналу.")
else:
print("User not in a voice channel.")
await interaction.send(f"Вы должны находиться в голосовом канале для воспроизведения музыки.")
else:
print("No tracks found.")
await interaction.send(f"По вашему запросу ничего не найдено.")
@bot.command(guild_ids=[])
async def skip(interaction: nextcord.Interaction):
vc: wavelink.Player = interaction.guild.voice_client
await vc.stop()
await interaction.response.send_message(f"Песня скипнута")
@bot.command(guild_ids=[])
async def pause(interaction: nextcord.Interaction):
vc: wavelink.Player = interaction.guild.voice_client
if vc.is_playing():
await vc.pause()
await interaction.response.send_message(f"Песня остановлена")
else:
await interaction.response.send_message(f"Песня уже остановлена")
bot.run("token")
错误:
机器人只是写道它无法连接到语音通道,我已经尝试制作一个机器人大约一个月了,但总是会出现某种错误,然后它会连接和音乐等等......我累了
PS C:\Users\comp\Desktop\137077897> py bot.py
C:\Users\comp\AppData\Local\Programs\Python\Python310\lib\site-packages\nextcord\health_check.py:20: DistributionWarning: discord.py is installed which is incompatible with nextcord. Please remove this library by using `pip3 uninstall discord.py`
warn(message, DistributionWarning, stacklevel=0)
INFO:nextcord.client:logging in using static token
INFO:nextcord.gateway:Shard ID None has sent the IDENTIFY payload.
INFO:nextcord.gateway:Shard ID None has connected to Gateway: ["gateway-prd-us-east1-d-rrjx",{"micros":252003,"calls":["id_created",{"micros":1025,"calls":[]},"session_lookup_time",{"micros":1714,"calls":[]},"session_lookup_finished",{"micros":16,"calls":[]},"discord-sessions-prd-2-165",{"micros":248555,"calls":["start_session",{"micros":196390,"calls":["discord-api-7986c7c7f6-qjzj5",{"micros":188641,"calls":["get_user",{"micros":18109},"get_guilds",{"micros":19045},"send_scheduled_deletion_message",{"micros":12},"guild_join_requests",{"micros":7343},"authorized_ip_coro",{"micros":14}]}]},"starting_guild_connect",{"micros":61,"calls":[]},"presence_started",{"micros":312,"calls":[]},"guilds_started",{"micros":157,"calls":[]},"guilds_connect",{"micros":1,"calls":[]},"presence_connect",{"micros":51602,"calls":[]},"connect_finished",{"micros":51608,"calls":[]},"build_ready",{"micros":23,"calls":[]},"clean_ready",{"micros":1,"calls":[]},"optimize_ready",{"micros":1,"calls":[]},"split_ready",{"micros":0,"calls":[]}]}]}] (Session ID: 19f80f97030e797ad068ad080de5e43c).
Bot Ready!
INFO:wavelinkcord.node:Lavalink version "3.7.9" connected for Node: YliFxRZUm8Jf
Failed to connect to voice channel.
答: 暂无答案
评论