首页 > 解决方案 > 如何制作带有标签的不和谐机器人

问题描述

当有人加入语音频道时,如何制作一个标记@role 的不和谐机器人?示例:@role {user} 已加入Support 1 Channel

标签: discorddiscord.py

解决方案


@bot.event
async def on_voice_state_update(member, before, after):
    # Checking if the member has joined channel
    if before.voice is None and after.voice is not None:
        # Getting the channel and a role
        channel = bot.get_channel(channel_id)
        role = member.guild.get_role(role_id)

        # Sending some info 
        await channel.send(f'{role.mention} {member.mention} has joined `{str(after.voice.channel)}`')

推荐阅读