【问题标题】:Python discord bot - join voice channelPython discord bot - 加入语音频道
【发布时间】:2020-10-16 18:53:12
【问题描述】:

我有兴趣使用 python 制作一个不和谐的机器人。 我正在尝试制作一个可以加入语音频道的机器人。 这是我的代码,我已经运行了它,但它不起作用。 我已经在网上做了一些研究,但我认为这段代码完全没问题?

   #Join Command
     @client.command()
     async def join(ctx):
         if(ctx.author.voice): #If in voice channel
            channel = ctx.author.voice.channel
            await channel.connect()
    
        else: #If not in voice channel
            await ctx.send("You must be in voice channel first !")

那么知道为什么我的代码不起作用吗? 这是我第一次使用python btw。

【问题讨论】:

    标签: python discord.py-rewrite


    【解决方案1】:
    @bot.command(name='join', invoke_without_subcommand=True)
    async def join(ctx):
       destination = ctx.author.voice.channel
       if ctx.voice_state.voice:
         await ctx.voice_state.voice.move_to(destination)
         return
    
       ctx.voice_state.voice = await destination.connect()
       await ctx.send(f"Joined {ctx.author.voice.channel} Voice Channel")
    

    这就是我们可以将不和谐机器人加入语音频道的方式。

    目的地是该人已经连接并希望将机器人添加到该频道的位置。

    【讨论】:

      猜你喜欢
      • 2022-01-23
      • 2021-01-05
      • 2020-11-04
      • 2020-11-03
      • 2020-06-26
      • 2017-06-22
      • 1970-01-01
      • 2020-12-21
      • 2020-10-07
      相关资源
      最近更新 更多