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

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

鎖定命令 Discord.js

鎖定命令 Discord.js

嗶嗶one 2023-05-19 15:03:39
我最近為 discord.js 做了一個鎖定命令。但是,每當我運行命令時,我都會收到錯誤消息。這是代碼:module.exports = {    name: "lock",    description: "Lock",    async run(client, message, args) {        if (!message.member.hasPermission("KICK_MEMBERS")) return message.channel.send('You can\'t use that!')        function lock(message) {            let channel = message.channel;            const Guild = client.guilds.cache.get("751424392420130907");            if (!Guild) return console.error("Couldn't find the guild.");            const Role = Guild.roles.cache.find(role => role.name == "Verified");            channel.overwritePermissions(                Role, {                'SEND_MESSAGES': false            },                'Competitive has Ended'            )        }        lock(message)        message.channel.send('Channel Locked')    }}正如我之前提到的,每當我運行此命令時,我都會收到以下錯誤:(node:1354) UnhandledPromiseRejectionWarning: TypeError [INVALID_TYPE]: Supplied overwrites is not an Array or Collection of Permission Overwrites.    at TextChannel.overwritePermissions (/home/runner/SweatyBeautifulHelpfulWorker/node_modules/discord.js/src/structures/GuildChannel.js:208:9)    at lock (/home/runner/SweatyBeautifulHelpfulWorker/commands/lock.js:14:11)    at Object.run (/home/runner/SweatyBeautifulHelpfulWorker/commands/lock.js:21:1)    at Client.<anonymous> (/home/runner/SweatyBeautifulHelpfulWorker/index.js:77:42)    at Client.emit (events.js:327:22)    at Client.EventEmitter.emit (domain.js:483:12)    at MessageCreateAction.handle (/home/runner/SweatyBeautifulHelpfulWorker/node_modules/discord.js/src/client/actions/MessageCreate.js:31:14)    at Object.module.exports [as MESSAGE_CREATE] (/home/runner/SweatyBeautifulHelpfulWorker/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
查看完整描述

5 回答

?
白衣染霜花

TA貢獻1796條經驗 獲得超10個贊

你應該這樣做,你的代碼看起來很長:


 if (!message.member.roles.cache.some(role => role.name === 'Moderator')) return;

 message.channel.updateOverwrite(message.channel.guild.roles.everyone, { SEND_MESSAGES: false })

 message.channel.send(`Successfully locked **${message.channel.name}**`)

從你的角色中替換message.channel.guild.roles.everyone。


查看完整回答
反對 回復 2023-05-19
?
桃花長相依

TA貢獻1860條經驗 獲得超8個贊

這不是你如何更新權限而不是這個:


channel.overwritePermissions(

? ? ? ? ? ? Role, {

? ? ? ? ? ? 'SEND_MESSAGES': false

? ? ? ? },

? ? ? ? ? ? 'Competitive has Ended'

? ? ? ? )

用這個:


channel.overwritePermissions([

? ? ? ? {

? ? ? ? id: roleId,

? ? ? ? deny: ['SEND_MESSAGES']

? ? ? ? }]

? ? ? ? ,'Competitive has Ended'

? ? )


查看完整回答
反對 回復 2023-05-19
?
三國紛爭

TA貢獻1804條經驗 獲得超7個贊

下面這段代碼可能對你有幫助


channel.overwritePermissions(

    [

        {

            id: roleId,

            deny: [

                'SEND_MESSAGES'

            ]

        }

    ]

        , 'Mark my question'

)```


查看完整回答
反對 回復 2023-05-19
?
慕無忌1623718

TA貢獻1744條經驗 獲得超4個贊

你也應該使用updateOverwrite而不是overwritePermissions。


例子:


module.exports = {

    name: "lock",

    description: "Lock",


    run(client, message, args) {

       const targetChannel = message.mentions.channels.first() || message.channel;


        // Guild ID is the same as the everyone role ID

        const everyoneID = message.guild.id;


        targetChannel.updateOverwrite(everyoneID, {

            SEND_MESSAGES: false,

        });


        targetChannel.send(`**${targetChannel.name}** has been locked :lock:`);

    }

}

也不需要它是異步函數,因為您沒有在代碼中使用 await 。



查看完整回答
反對 回復 2023-05-19
?
一只斗牛犬

TA貢獻1784條經驗 獲得超2個贊

您只需調用以下行即可刪除當前頻道的發送權限:


const Role = guild.roles.find("name", "Verified ");


message.channel.overwritePermissions(role,{ 'SEND_MESSAGES': false })

如果你想制作解鎖頻道命令,只需在命令下添加:


const Role = guild.roles.find("name", "Verified ");


message.channel.overwritePermissions(role,{ 'SEND_MESSAGES': true})


查看完整回答
反對 回復 2023-05-19
  • 5 回答
  • 0 關注
  • 261 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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