为了账号安全,请及时绑定邮箱和手机立即绑定

锁定命令 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 关注
  • 178 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信