gpt4 book ai didi

python - 我想让我的不和谐机器人每小时加入一次语音聊天

转载 作者:行者123 更新时间:2023-12-04 23:20:20 25 4
gpt4 key购买 nike

我想每小时加入一次语音聊天并播放 mp3 文件,使用 discord.py

    @client.command()
async def join(ctx):
channel = ctx.author.voice.channel
voice = await channel.connect()
source = FFmpegPCMAudio('sound.mp3')
player = voice.play(source)

最佳答案

documentation's 的略微修改版本例子是:

from discord.ext import tasks, commands

class MyCog(commands.Cog):
def cog_unload(self):
self.joiner.cancel()

@tasks.loop(hours=1)
async def joiner(self):
channel = self.bot.get_channel(<id>)
voice = await channel.connect()
source = FFmpegPCMAudio('sound.mp3')
player = voice.play(source)

关于python - 我想让我的不和谐机器人每小时加入一次语音聊天,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68154580/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com