[英]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:笔记:
I might have missed some specific case you may want to take into account.我可能错过了一些您可能想要考虑的特定案例。 Check if you need to monitor something else检查是否需要监视其他内容
Your bot needs to have the voice_states intent enable您的机器人需要启用voice_states 意图
References:参考:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.