【问题标题】:Invite Bot to voice channel without using ctx在不使用 ctx 的情况下邀请 Bot 加入语音频道
【发布时间】:2021-05-18 19:57:39
【问题描述】:

我想知道如果特定语音频道中有一个成员,是否有办法让机器人加入 vc。我不希望用户使用命令来激活它。

async def arrive(ctx):
bruh = client.get_channel(748685131119591506)
curMembers = []
for member in bruh.members:
    curMembers.append(member)
channel = ctx.author.voice.channel
vc = await channel.connect()
boi = len(curMembers)
room = discord.Object(748685131119591506)
if boi == 1 and room: 
    await ctx.send("Dang everyone left :pensive:")
    await ctx.voice_client.disconnect()
elif boi == 1:
    await vc.move_to(room)


@tasks.loop(seconds=5)
async def looparrive(ctx):
    client.loop.create_task(arrive(ctx))

这个到达代码附加到client.command(),因为我不知道如何以任何其他方式传递上下文。该机器人只需要在一台服务器上工作,因此我们将不胜感激。

【问题讨论】:

    标签: python-3.x discord.py


    【解决方案1】:

    你可以做类似这样的事情:

    async def arrive():
        guild = client.get_guild(GUILDID)
        text_channel = client.get_channel(TEXTCHANNELID)
        voice_channels = guild.voice_channels
        for vc in voice_channels:
            if len(vc.members) == 1:
                vClient = await vc.connect()
                await text_channel.send("Dang everyone left :pensive:")
                await vClient.disconnect()
    
    
    @tasks.loop(seconds=50)
    async def looparrive():
        await arrive()
    

    5 秒的循环似乎有点激进,所以我建议提高它以避免这个过程被大量垃圾邮件。

    【讨论】:

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