Discord.py 设备温度指令

Discord.py device temperature command

我想为我的机器人发出一个命令来帮助我检查我的 Raspberry Pi 体温。我试图发出命令,ctx.send(os.system('vcgencmd measure_temp')) 但它发送“0”。我只试了 ctx.send(vcgencmd measure_temp) 但还是不行,有人可以帮我吗?

os.system return是命令的return代码。使用 subprocess.run 代替获取标准输出(我假设那是 vsgencmd 输出的地方):

await ctx.send(subprocess.run(["vcgencmd", "measure_temp"], stdout=subprocess.PIPE).stdout.decode("utf-8").strip())

.decode("utf-8") 将标准输出从 bytes 转换为 str 并且 strip 删除尾随的换行符。