python-3.x - 如何让我的不和谐机器人从我的电脑播放音频文件
问题描述
我试图让我的机器人在语音聊天中播放音频文件,而不是 youtube 视频。令人惊讶的是,我真的找不到任何工作帮助。
@client.command()
async def play(ctx, *args):
if len(args) == 0:
await ctx.send("Specify something then")
else:
#server = ctx.message.server
#voice_client = client.voice_client_in(server)
voice_player = await ctx.message.author.voice.channel.connect()
if args[0] == "chulp":
print("Playing chulp")
source = discord.FFmpegPCMAudio("Core files\\Sounds\\chulpy.mp3")
player = voice_player.play(source)
player.start()
我总是收到这个错误:
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'NoneType' object has no attribute 'start'
解决方案
你做错了。你必须这样做——
if args[0] == "chulp":
print("Playing chulp")
player = voice_player.create_ffmpeg_player("Core files\\Sounds\\chulpy.mp3")
player.start()
我不确定,但这也可以-
if args[0] == "chulp":
print("Playing chulp")
voice_player.play(discord.FFmpegPCMAudio("Core files\\Sounds\\chulpy.mp3"))
我认为您结合了来自 2 个不同来源的代码。
推荐阅读
- python-2.7 - 如何在无效 JSON 文档中用引号将特定键的值括起来
- javascript - 尝试在 Google Apps 脚本中将 Stripe API 密钥添加到 UrlFetchApp 时收到 401“截断服务器”错误
- java - 找不到路径时如何返回状态码 400
- json - 如何从python3中的JSON文件中获取所有嵌套字段的列表?
- pandas - 旋转数据框
- android - 为什么当协程尝试进入 Dispatchers.Main 时应用程序终止?
- sql - 如何将转换为 UTC 的当前时间戳与在 Oracle SQL 上转换为 UTC 的另一个时间戳进行比较?
- matlab - Fortran“全局”变量与 Matlab 函数句柄
- geolocation - 如何从 Here API 更新不正确的标准化位置
- java - 如何按顺序制作