簡體   English   中英

如何在 discord.js v12 中鎖定此命令?

[英]How can I owner lock this command in discord.js v12?

我正在嘗試制作這個命令,所以只有我可以運行它,到目前為止還沒有運氣。

client.on("message", message => { 
    const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
    const command = args.shift().toLowerCase()

    if (command === "test") {
        console.log((chalk.yellow)`You ran a command: test`)
        message.channel.send('test')
    }
});

我嘗試使用

if (!message.author.id === config.ownerID) return;

if (message.author.id !== config.ownerID) return;

當我使用第一個時,命令有效,但每個人都能運行它,而當我使用第二個時,根本沒有人能夠運行它。 我沒有收到任何錯誤日志或崩潰。 有人知道正確的代碼嗎?

正如我在上面的評論中提到的,第一個肯定是不正確的,因為您正在使用邏輯 NOT 運算符 ( ! ) 將message.author.id轉換為 boolean。 如果config.ownerID是字符串,您的第二次嘗試可能會起作用,但您不能將字符串與數組進行比較。

如果你的config.ownerID是一個 ID 數組,你可以使用includes()方法來檢查message.author.id是否包含在給定的數組中:

if (config.ownerID.includes(message.author.id)) return

暫無
暫無

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

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