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

时间:2021-06-27 19:20:52

标签: python python-3.x ffmpeg discord.py

我想每小时加入一次语音聊天并播放 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)

1 个答案:

答案 0 :(得分:0)

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)