锁定命令 Discord.js

我最近为 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)


哔哔one
浏览 179回答 5
5回答

白衣染霜花

你应该这样做,你的代码看起来很长:&nbsp;if (!message.member.roles.cache.some(role => role.name === 'Moderator')) return;&nbsp;message.channel.updateOverwrite(message.channel.guild.roles.everyone, { SEND_MESSAGES: false })&nbsp;message.channel.send(`Successfully locked **${message.channel.name}**`)从你的角色中替换message.channel.guild.roles.everyone。

桃花长相依

这不是你如何更新权限而不是这个:channel.overwritePermissions(            Role, {            'SEND_MESSAGES': false        },            'Competitive has Ended'        )用这个:channel.overwritePermissions([        {        id: roleId,        deny: ['SEND_MESSAGES']        }]        ,'Competitive has Ended'    )

三国纷争

下面这段代码可能对你有帮助channel.overwritePermissions(&nbsp; &nbsp; [&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; id: roleId,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; deny: [&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'SEND_MESSAGES'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ]&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; ]&nbsp; &nbsp; &nbsp; &nbsp; , 'Mark my question')```

慕无忌1623718

你也应该使用updateOverwrite而不是overwritePermissions。例子:module.exports = {&nbsp; &nbsp; name: "lock",&nbsp; &nbsp; description: "Lock",&nbsp; &nbsp; run(client, message, args) {&nbsp; &nbsp; &nbsp; &nbsp;const targetChannel = message.mentions.channels.first() || message.channel;&nbsp; &nbsp; &nbsp; &nbsp; // Guild ID is the same as the everyone role ID&nbsp; &nbsp; &nbsp; &nbsp; const everyoneID = message.guild.id;&nbsp; &nbsp; &nbsp; &nbsp; targetChannel.updateOverwrite(everyoneID, {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SEND_MESSAGES: false,&nbsp; &nbsp; &nbsp; &nbsp; });&nbsp; &nbsp; &nbsp; &nbsp; targetChannel.send(`**${targetChannel.name}** has been locked :lock:`);&nbsp; &nbsp; }}也不需要它是异步函数,因为您没有在代码中使用 await 。

一只斗牛犬

您只需调用以下行即可删除当前频道的发送权限: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})
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript