不和谐机器人在完成音乐之前断开连接



我使用DiscordUtils为这个确切的bot。音乐在中途播放(每首歌),并在机器人显示没有歌曲播放的信息时停止。这是我的代码(没有错误显示)。

我似乎找不到关于这个包含关于DiscordUtils的信息的任何信息。我只得到YouTube-DL的结果,可悲的是它的工作方式不同。是否有任何确切的解决方案,这个问题,这是一个FFMPEG错误?

import discord
from discord.ext import commands
from discord.ext.commands import has_permissions
from discord import Client, Intents, Embed
from discord.ext.commands.core import command
from discord_slash import SlashCommand, SlashContext
from discord_slash.utils.manage_commands import create_choice, create_option
import DiscordUtils
import ffmpeg

music = DiscordUtils.Music()
activity = discord.Game(name="around. Use /help")
client = commands.Bot(command_prefix='?', activity=activity)
slash = SlashCommand(client, sync_commands=True)
@client.command()
async def join(ctx):
voicetrue = ctx.author.voice
if voicetrue is None:
return await ctx.send('You are not currently in a voice channel. :exclamation:')
await ctx.author.voice.channel.connect()
await ctx.send('Joined the voice chat you are in. :white_check_mark:')
@client.command()
async def leave(ctx):
voicetrue = ctx.author.voice
mevoicetrue = ctx.guild.me.voice
if voicetrue is None:
return await ctx.send('You are not currently in the same voice channel as I am.')
if mevoicetrue is None:
return await ctx.send('Im not currently in any voice channel!')
await ctx.voice_client.disconnect()
await ctx.send('I have disconnected from the voice channel.')
@client.command()
async def play(ctx, *, url):
player = music.get_player(guild_id=ctx.guild.id)
if not player:
player = music.create_player(ctx, ffmpeg_error_bettercix=True)
if not ctx.voice_client.is_playing():
await player.queue(url, search=True)
song = await player.play()
await ctx.send(f'Playing **{song.name}** :notes:')
else:
song = await player.queue(url, search=True)
await ctx.send(f'Ive added **{song.name}** to the queue!')
@client.command()
async def queue(ctx):
player = music.get_player(guild_id=ctx.guild.id)
await ctx.send(f"The music queue currently is: **{', '.join([song.name for song in player.current_queue()])}**")
@client.command()
async def pause(ctx):
player = music.get_player(guild_id=ctx.guild.id)
song = await player.pause()
await ctx.send(f'Paused **{song.name}** :pause_button:')
@client.command()
async def resume(ctx):
player = music.get_player(guild_id=ctx.guild.id)
song = await player.resume()
await ctx.send(f'Resumed **{song.name}** :arrow_forward:')
@client.command()
async def loop(ctx):
player = music.get_player(guild_id=ctx.guild.id)
song = await player.toggle_song_loop()
if song.is_looping:
return await ctx.send(f'{song.name} will now start looping. :repeat:')
else:
return await ctx.send(f'{song.name} will no longer loop. :no_entry:')
@client.command()
async def nowplaying(ctx):
player = music.get_player(guild_id=ctx.guild.id)
song = player.now_playing()
if song.name is None:
await ctx.send(song.name + ' is currently playing.')
@client.command()
async def remove(ctx, index):
player = music.get_player(guild_id=ctx.guild.id)
song = await player.remove_from_queue
await ctx.send(f'Removed {song.name} from the song queue!')

@slash.slash(
name="hello",
description="Hello there!",
guild_ids=[822512275331219517, 708384142978711582, 747869167889285180]
)
async def _hello(ctx:SlashContext):
await ctx.send("Hi! test command")
@slash.slash(
name="help",
description="Recieve help using Anix",
guild_ids=[822512275331219517, 708384142978711582, 747869167889285180]
)
async def _help(ctx:SlashContext):
embed=discord.Embed(title="Commands to get you going", description="", color=0xff131a)
embed.set_author(name="Anix Help")
embed.add_field(name="?play", value="use this command whilst in a voice channel to start music", inline=False)
embed.add_field(name="?join", value="make Anix join your voice channel", inline=False)
embed.add_field(name="?leave", value="make Anix leave your voice channel", inline=False)
embed.add_field(name="?queue", value="check the music queue", inline=False)
embed.add_field(name="?pause", value="pauses the current song that's playing", inline=False)
embed.add_field(name="?resume", value="resumes a paused song", inline=False)
embed.add_field(name="?loop", value="loops the current song (type again to stop loop)", inline=False)
embed.add_field(name="?nowplaying", value="check the song that's currently playing", inline=True)
embed.add_field(name="?remove", value="removes the currently playing song from the queue", inline=True)
await ctx.send(embeds=[embed])
client.run('token')

通过移除import ffmpeg,断开连接的问题不再发生。所有的命令都可以正常工作。

最新更新