简体   繁体   中英

Lock command discord.js v12

I'm trying to make a lock command here is my code:

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;
      let roles = message.guild.roles;
      let testRole = roles.find('Verified');
      channel.overwritePermissions(
        testRole, {
          'SEND_MESSAGES': false
        },
        'Competitive has Ended'
      )
      lock(message).catch(error => console.log(error));
    }
    message.channel.send('Channel Locked')
  }
}

However, on running this code I get no response from the bot neither does it carry out the function. I don't get any error too. Can toy help me out? Thanks in advance!

You define a function lock , but you call it in the wrong place. You try to call the lock function within the function itself, which won't work. If you change your code to the following it should work:

if (!message.member.hasPermission("KICK_MEMBERS")) return message.channel.send('You can\'t use that!')
function lock(message) {
  let channel = message.channel;
  let roles = message.guild.roles;
  let testRole = roles.find('Verified');
  channel.overwritePermissions(
    testRole, {
      'SEND_MESSAGES': false
    },
    'Competitive has Ended'
  )
}
lock(message).catch(error => console.log(error));
message.channel.send('Channel Locked')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM