简体   繁体   English

我 go 如何在 python 中制作一个 discord 机器人,当特定的人加入特定的语音频道时它会提醒我

[英]How do I go about making a discord bot in python that alerts me when a specific person joins a specific voice channel

I've been developing a bot for a while now and I want the bot to notify or alert me when a specific member of the server joins a specific voice channel in the server.我开发机器人已经有一段时间了,我希望机器人在服务器的特定成员加入服务器中的特定语音通道时通知或提醒我。 I know that there needs to be specification of the channel_id and the user_id but how do i go about writing it.我知道需要指定 channel_id 和 user_id,但我 go 如何编写它。 I want the bot to, either direct message me or like, mention me in a specific channel to alert me when that someone joins that specific channel.我希望机器人直接向我发送消息或喜欢在特定频道中提及我,以便在有人加入该特定频道时提醒我。 Does it make sense?是否有意义? It's a very specific command for a very specific purpose.这是一个非常具体的命令,用于非常具体的目的。 How do I go about adding that to my bot??我如何 go 将其添加到我的机器人中?

I watched a couple tutorials but I never seem to find what I was expecting.我看了几个教程,但我似乎从来没有找到我所期待的。

You can use the on_voice_state_update event that is called when a Member changes their VoiceState :您可以使用当Member更改其VoiceState时调用的on_voice_state_update事件:

@bot.event
async def on_voice_state_update(member : discord.Member, before : discord.VoiceState, after : discord.VoiceState):
    member_id = 123456789                                               # The id of the specific member
    channel_id = 987654321                                              # The id of the specific voice channel
    owner_id = 192837465                                                # The id of the user (you) the bot has to dm when the specific member join the specific channel
    
    if member.id != member_id: return                                   # Continue only if the member that triggered the event is the specific member
    if not after.channel or channel_id != after.channel.id: return      # Continue only if the channel that the member is conected to is the specific voice channel
    if before.channel and before.channel.id == after.channel.id: return # Continue only if the member that triggered the event wasn't already connected to the specific voice channel
    
    owner = bot.get_user(owner_id)
    await owner.send('The specific member has connected to the specific voice channel')

Notes:笔记:

  1. I might have missed some specific case you may want to take into account.我可能错过了一些您可能想要考虑的特定案例。 Check if you need to monitor something else检查是否需要监视其他内容

  2. Your bot needs to have the voice_states intent enable您的机器人需要启用voice_states 意图

References:参考:

  1. on_voice_state_update event on_voice_state_update 事件

  2. VoiceState class 语音状态 class

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当特定人加入语音频道时,如何制作加入语音频道的机器人? - How do I make a bot that joins a voice channel when a specific person joins a voice channel? 我将如何制作一个机器人来计算语音频道中有多少人的名字以“5”开头(discord.py) - How would I go about making a bot that counts how many peoples name starts with a '5' in a voice channel (discord.py) 如何让我的 Discord 机器人在特定 mp3 文件的时间长度内停留在语音通道中? - How do I make my Discord bot stay in the voice channel for the length of time of a specific mp3 file? 当语音频道中的人说话时,我可以让 discord python 机器人识别吗? - Can I make a discord python bot recognize when a person in a voice channel talks? 如何制作一个 discord 机器人来记录特定频道的聊天记录? - How do I make a discord bot that logs chats in a specific channel? 如何让我的 Discord 机器人提及频道中的特定人员? - How can i make my Discord bot mention a specific person in the channel? 当特定用户在频道中发送消息时,如何让我的 discord 机器人响应? - How do I make my discord bot respond when a specific user sends a message in the channel? 用 Python 编程一个 Discord 机器人——如何让它加入语音频道? - Programming a Discord bot with Python- How do I make it join a voice channel? Python discord 机器人警告特定人员 - Python discord bot warn specific person Discord 机器人加入语音频道静音 - Discord Bot joins voice channel muted
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM