【发布时间】:2021-09-28 16:37:04
【问题描述】:
看看这段代码:
async def playSound(ctx, channel, file, bot, connected):
ctx = ctx.message
vc = await connected.channel.connect()
await ctx.channel.send(embed = returnembed(preset = 'playingSound', info = str(channel)))
player = vc.create_ffmpeg_player(file)
player.start()
while not player.is_done():
await asyncio.sleep(1)
player.stop()
await vc.disconnect()
await os.remove(file)
Notes:
ctx = ...well umm context... more specifically:
@bot.command(pass_context = True)
async def foo(ctx):
pass
connected = ctx.author.voice
file = WAV_FILENAME
bot = commands.Bot(command_prefix= settings['callbotprefix_str'])
channel = ctx.author.voice.channel
(注意:当我测试这个时,我确实在一个语音通道中。)
我正在尝试在语音通道中播放本地音频文件。虽然机器人每次都成功加入语音频道,并且我可以确认文件没有损坏,但我收到了一个非常“pleating”的异常:
Ignoring exception in command foo:
Traceback (most recent call last):
File "discord_package", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "bot_file", line 224, in tts
await playsound(message, connected.channel, fileName, bot, connected)
File "bot_file", line 318, in playsound
player = vc.create_ffmpeg_player(file)
AttributeError: 'VoiceClient' object has no attribute 'create_ffmpeg_player'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "discord_package", line 939, in invoke
await ctx.command.invoke(ctx)
File "whatever_the_core_thing_is", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "the_core_thing_again", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'VoiceClient' object has no attribute 'create_ffmpeg_player'
【问题讨论】:
标签: python discord.py