問題描述
我正在使用 discord.js.有沒有辦法檢查一個公會是否有一個具有特定名稱的頻道,如果有,將該頻道 id 存儲到一個變量中?我正在嘗試創建一個命令,將其操作記錄到名為logs"的頻道(如果存在).
I am using discord.js. Is there a way to check if a guild has a channel with a specific name, and if so, store that channels id to a variable? I am trying to make a command that logs it's actions to a channel with the name 'logs' if it exists.
推薦答案
A Guild 有一個 channels
屬性返回 Collection.使用 Collection.find()
,您可以通過比較Channel.name
在謂詞函數中.如果找到一個頻道,你可以閱讀它的 id
屬性來檢索其雪花 ID.
A Guild has a channels
property which returns a Collection of GuildChannels. Using Collection.find()
, you can search for the channel by name by comparing Channel.name
in the predicate function. If a channel is found, you can read its id
property to retrieve its Snowflake ID.
例如...
const channel = /* Guild */.channels.find(c => c.name === 'some-name');
const id = channel ? channel.id : null;
這篇關于discord.js 檢查公會是否有一個具有特定名稱的頻道,如果有,則將該頻道 ID 存儲到一個變量中的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!