ユーザーが特定の音声チャネルに参加したときに特定のチャネルに埋め込まれたメッセージを送信するdiscord.pyボットを作成する方法

ごめんなさい

私はdiscord.pyを学んでおり、(@ userが参加しました!)などの埋め込みメッセージを送信するボットを特定のテキストチャネルにのみ参加させたいと考えています(例:(#music-cnsole)ユーザーが特定の音声チャネルに参加した場合(音楽)。 vc)

  • このような ここに画像の説明を入力してください

ユーザーが参加するとき

  • また ここに画像の説明を入力してください

ユーザーが離れるとき

@client.event
async def on_voice_state_update(member, before, after):
YMO4
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 ドキュメント内のイベント

多くの編集をご容赦ください。

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

Related 関連記事

ホットタグ

アーカイブ