【问题标题】:how to make a discord.py bot that send embedded message in particular channel when user join a particular voice channel当用户加入特定语音频道时,如何制作一个在特定频道中发送嵌入消息的 discord.py 机器人
【发布时间】:2021-04-05 00:26:14
【问题描述】:

我正在学习 discord.py,我想制作发送嵌入式消息的机器人。(@user 已加入!)仅在特定的文本频道中加入,例如。(#music-cnsole)当用户加入特定的语音频道时,例如。 (音乐.vc)

  • 喜欢这个

用户加入时

  • 还有

当用户离开时

@client.event
async def on_voice_state_update(member, before, after):

【问题讨论】:

标签: discord.py


【解决方案1】:
channelId = 1234567891011 # Your text channel id here
voiceChannelId = 1234567891011 # Your voice channel id here

@bot.event
async def on_voice_state_update(member, before, after):
    if ((before.channel != None and before.channel.id == voiceChannelId) or (after.channel != None and after.channel.id == voiceChannelId)): # if connected/disconected to voiceChannelId channel
        channel = bot.get_channel(channelId) # gets channel object
        if (before.channel == None and after.channel != None): # if user connect
            channel.send(f"{member.mention} connected to voice {after.channel.name}") # send message to channel
        elif (before.channel != None and after.channel == None): # if user disconnect
            channel.send(f"{member.mention} disconnect from voice {before.channel.name}") # send message to channel

on_voice_state_update event in docs

请原谅许多编辑。

【讨论】:

    猜你喜欢
    • 2021-07-13
    • 1970-01-01
    • 2020-10-04
    • 2021-02-28
    • 1970-01-01
    • 1970-01-01
    • 2021-08-18
    • 2021-06-19
    • 1970-01-01
    相关资源
    最近更新 更多