用户输入特定语音通道时更改discord.py Bot的状态

时间:2020-10-10 08:29:57

标签: python discord discord.py discord.py-rewrite

我希望每当用户加入频道时使漫游器上线,并在用户离开频道时使其脱机。我对discord.js很陌生,但这是我的代码:

import discord
from discord.ext import commands

client = commands.Bot(command_prefix = '.')

@client.event
async def on_ready():
    await client.change_presence(status=discord.Status.offline)
    print("Bot ready")

@client.event
async def on_voice_state_update(member, before, after):
    if not before.channel:
        if after.channel.id == [""Channel ID 1""] or after.channel.id == [""Channel ID 2""]:
                await client.change_presence(status=discord.Status.online, activity=discord.Activity(type=discord.ActivityType.listening, name="users | Ready to mute"))
                print(f'{member.name} joined {after.channel.name}')
    elif before.channel and after.channel:
        if before.channel != after.channel:
            if after.channel.id == [""Channel ID 1""] or after.channel.id == [""Channel ID 2""]:
                if member.roles[1].name == "Admin" or member.roles[1].name == "Moderator":
                    await client.change_presence(status=discord.Status.online, activity=discord.Activity(type=discord.ActivityType.listening, name="users | Ready to mute"))
                    print(f'{member.name} joined {after.channel.name}')
    elif before.channel and not after.channel:
            if member.roles[1].name == "Admin" or member.roles[1].name == "Moderator":
                await client.change_presence(status=discord.Status.offline)
                print(f'{member.name} left {before.channel.name}')

client.run("Key")

当然,我将用通道ID替换““通道ID 1”“和”“通道ID 2”“,并用我的认证密钥替换”“密钥”。

我遇到的问题是事件似乎没有被注册。

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

进行一些更改,id是一个int而不是一个字符串,如此处所述。所以 您应该将channel.id与一个整数而不是一个列表进行比较 项目。

– InsertCheesyLine