我想做一个像谷歌助手这样的小机器人。它可以连接到语音通道并播放一些音频。但这只是一个音乐机器人,我想录制音频以对其进行分析,并且(因为机器人在 RaspberryPi 上)根据我在语音通道中所说的内容打开或关闭 LED。我目前的解决方案只需要一个命令,而且只有我理解它。我找到了一种记录方法 (https://github.com/Sheepposu/discord.py/blob/master/examples/receive_vc_audio.py),但出现以下错误: 属性错误:“VoiceClient”对象没有“start_recording”属性 这是我的代码:
import discord
from discord.ext import commands
import time
import asyncio
import rgb #my own rgb-led-thing
def led(stat):
if stat == "on":
rgb.red(1)
if stat == "off":
rgb.red(0)
class add(commands.Cog):
def __init__(self, client):
self.client = client
@commands.command()
async def test(self, ctx):
if not ctx.message.author.voice:
# Exiting if the user is not in a voice channel
return await ctx.send('Youre not in a vc')
channel = ctx.author.voice.channel
vc = await channel.connect()
vc.start_recording(self.on_stopped, msg.channel)
vc.play(discord.FFmpegPCMAudio("rickroll.mp3")) #this is from my old version of this cog but i left it here for testing because if it doesnt plays i know smth is wrong
await asyncio.sleep(19) #exactly the duration of the song
vc.stop_recording()
await ctx.send("**TEST TEST TEST TEST TEST**")
await ctx.voice_client.disconnect()
def setup(dc):
dc.add_cog(add(dc))