所以我试图在Python中制作一个Disord Bot,它会自动加入一个语音频道,并循环播放我自己的音乐。到目前为止,它正在加入频道,洗牌列表,因此音乐是随机的,但是当我尝试编写代码时,它会在一首歌之后播放下一首歌,它会粉碎并且不播放任何东西(尽管它正在加入频道)
import discord
import random
from discord.ext import commands
from discord import FFmpegPCMAudio
#playlist as a list
queue = [FFmpegPCMAudio('Iceland1.wav'), FFmpegPCMAudio('Iceland2.wav'), FFmpegPCMAudio('Iceland3.wav'), FFmpegPCMAudio('Iceland4.wav'),
FFmpegPCMAudio('Iceland5.wav'), FFmpegPCMAudio('Iceland6.wav'), FFmpegPCMAudio('Iceland7.wav'), FFmpegPCMAudio('Iceland8.wav'),
FFmpegPCMAudio('Iceland9.wav'), FFmpegPCMAudio('Iceland10.wav'), FFmpegPCMAudio('Norway1.wav'), FFmpegPCMAudio('Norway2.wav'),
FFmpegPCMAudio('Norway3.wav'), FFmpegPCMAudio('Norway4.wav'), FFmpegPCMAudio('Norway5.wav'), FFmpegPCMAudio('Norway6.wav'),
FFmpegPCMAudio('Norway7.wav'), FFmpegPCMAudio('Norway8.wav'), FFmpegPCMAudio('Norway9.wav'), FFmpegPCMAudio('Norway10.wav'),
FFmpegPCMAudio('Norway11.wav'), FFmpegPCMAudio('Presents1.wav'), FFmpegPCMAudio('Presents2.wav'), FFmpegPCMAudio('Presents3.wav'),
FFmpegPCMAudio('Presents4.wav'), FFmpegPCMAudio('Presents5.wav'), FFmpegPCMAudio('Presents6.wav'), FFmpegPCMAudio('Presents7.wav'),
FFmpegPCMAudio('Presents8.wav'), FFmpegPCMAudio('Presents9.wav'), FFmpegPCMAudio('Presents10.wav'), FFmpegPCMAudio('Autumn1.wav'),
FFmpegPCMAudio('Autumn2.wav'), FFmpegPCMAudio('Autumn3.wav'), FFmpegPCMAudio('Autumn4.wav'), FFmpegPCMAudio('Autumn5.wav'),
FFmpegPCMAudio('Autumn6.wav'), FFmpegPCMAudio('Autumn7.wav'), FFmpegPCMAudio('Autumn8.wav'), FFmpegPCMAudio('Covers1.wav'),
FFmpegPCMAudio('Covers2.wav'), FFmpegPCMAudio('Covers3.wav'), FFmpegPCMAudio('Covers4.wav'), FFmpegPCMAudio('Covers5.wav'),
FFmpegPCMAudio('Covers6.wav'), FFmpegPCMAudio('Covers7.wav'), FFmpegPCMAudio('Covers8.wav'), FFmpegPCMAudio('Covers9.wav'),
FFmpegPCMAudio('Covers10.wav'), FFmpegPCMAudio('Covers11.wav'), FFmpegPCMAudio('Covers12.wav')]
intents = discord.Intents.default()
intents.message_content = True
client = commands.Bot(command_prefix='>', intents=intents)
@client.event
async def on_ready():
global voice
print("The Matt Bot is ready")
print("--------------------------")
await client.change_presence(activity=discord.Game('Matt Krupa')) #makes my bot play Matt Krupa
channel = client.get_channel(thechannelid) #geting channel ID
voice = await channel.connect() #connecting to channel
random.shuffle(queue) #randomazing the playlist
def after_song(): #moving the first song to the end so its on loop, and playling the next one
queue.append(queue[0])
del queue[0]
player = await voice.play(queue[0], after=await after_song())
player = await voice.play(queue[0], after=await after_song()) #plays song from the playlist, after the song doing the after_song() function
client.run(mytokenidontwanttoshowitsry)
我想让它在无限循环中播放所有歌曲,我找不到如何正确检测歌曲的结尾…
你试过这个吗:
after=await, after_song()
这可能是问题,因为它可能无法识别两个参数之间的空间