当用户进入特定的语音频道时,更改不和谐.py Bot的状态



我想让机器人在用户加入频道时上线,在用户离开频道时离线。我是不和谐.py的新手,但这是我的代码:

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 1"amp"quot;信道ID 2"具有信道ID和"键";使用我的身份验证密钥。

我遇到的问题是这些活动似乎没有注册。

谢谢你的帮助!

经过几次更改,id是int,而不是这里解释的字符串。所以您应该将channel.id与一个整数进行比较,而不是列表项目

–插入CheesyLine

最新更新