提问者:小点点

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


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

我似乎找不到任何包含有关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')

共1个答案

匿名用户

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