亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么我的discord.py 事件沒有被調用?

為什么我的discord.py 事件沒有被調用?

開滿天機 2023-10-18 15:45:10
我希望讓機器人在用戶加入頻道時上線,并在用戶離開頻道時離線。我對discord.js很陌生,但這是我的代碼:@client.eventasync def on_ready():    await client.change_presence(status=discord.Status.offline)    print("Bot ready")@client.eventasync def on_voice_state_update(member, before, after):    if before.channel is None and after.channel is not None:        if after.channel.id == [""Channel ID 1""] or after.channel.id == [""Channel ID 2""]:            await client.change_presence(status=discord.Status.online, activity=discord.Activity(type=discord.ActivityType.listening, name="users | Ready to mute"))            print("Bot done0")            print(member, "joined")@client.eventasync def on_voice_state_update(member, before, after):    if before.channel is not None and after.channel is None:        if before.channel.id == [""Channel ID 1""] or before.channel.id == [""Channel ID 2""]:            await client.change_presence(status=discord.Status.offline)            print("Bot done1")            print(member, "left")我當然會將“Channel ID 1”和“Channel ID 2”替換為通道 ID。謝謝你的幫助!
查看完整描述

1 回答

?
眼眸繁星

TA貢獻1873條經驗 獲得超9個贊

您有 2 個名為:“on_voice_state_update”的“def”,因此當此事件發生時,機器人不知道他必須調用哪一個。刪除 2 個“def”之一,并僅在一個名為“on_voice_state_update”的“def”中執行您想要的操作。


@client.event

async def on_voice_state_update(member, before, after):

    if before.channel is None and after.channel is not None:

        if after.channel.id == [""Channel ID 1""] or after.channel.id == [""Channel ID 2""]:

            await client.change_presence(status=discord.Status.online, activity=discord.Activity(type=discord.ActivityType.listening, name="users | Ready to mute"))

            print("Bot done0")

            print(member, "joined")

    elif before.channel is not None and after.channel is None:

            if before.channel.id == [""Channel ID 1""] or before.channel.id == [""Channel ID 2""]:

                await client.change_presence(status=discord.Status.offline)

                print("Bot done1")

                print(member, "left")


查看完整回答
反對 回復 2023-10-18
  • 1 回答
  • 0 關注
  • 132 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號