簡體   English   中英

discord.py 無法更改頻道名稱

[英]discord.py can't change the channel's name

所以最近我嘗試創建一個機器人,它可以根據服務器上有多少成員來更改語音頻道的名稱,但我最終得到了這個錯誤: await memberchannel.edit(name = ">> ᴍᴇᴍʙᴇʀꜱ: " + guild.member_count) AttributeError: 'NoneType' object has no attribute 'edit'

這是我的代碼,我不知道如何訪問 .edit 屬性:

async def on_member_join(member):
    guild = member.guild
    memberchannel : discord.VoiceChannel = get(guild.channels, id=MemberCounterChannel)
    await memberchannel.edit(name = ">> 👥ᴍᴇᴍʙᴇʀꜱ: " + guild.member_count)

我在 on_member_remove function 中做了同樣的事情。

使用on_member_join或其他與成員事件相關的事件必須要求啟用成員意圖。 這可以讓這些事件在它們是私有的時運行,並且應該小心使用。

可以從 Discord 開發人員門戶啟用意圖,從那里您只需確保已在“機器人”類別中的意圖中啟用Member 然后,您需要在定義機器人或客戶端的部分中定義和使用機器人代碼中的意圖:

intents = discord.Intents.default()
intents.members = True

client = commands.Bot(command_prefix='your bot prefix', intents=intents)

啟用意圖后,成員事件將起作用。 使用您的代碼, memberchannel也沒有定義,也不是 Discord 參數。

現在,這將通過其 ID 獲取您要編輯的頻道,並在用戶加入該用戶加入的公會的當前成員數時進行編輯。

async def on_member_join(member):
    member_channel = client.get_channel(channel id)
    await member_channel.edit(name=f"Members: {member.guild.member_count}")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM