Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

270
Visualizações
Basic discord.js lock command does not work

I was trying to make a basic lock command for my discord.js bot. I gave it the code for the command, made it only usable by users with a specific role, and lastly added the code for the lock itself.

// lock channel
const role = guild.roles.find("name", "👤︱Member");
client.on('message', msg => {
  if (msg.content === '.lock') {
msg.channel.send('Successfully locked the channel.');
if(!message.member.roles.some(r=>["👮︱Moderator", "🔱 ︱Trial Administrator"].includes(r.name))) return message.channel.send(`You dont have the moderator role!`)
message.channel.overwritePermissions(role,{ 'SEND_MESSAGES': false })
  }
});

If I started my bot, it would automatically shut down with this error message:

ReferenceError: guild is not defined

I have discord.js v12 if that helps. If the answer is that my discord.js version is outdated, then can you at least tell me any advice on the code too?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

As far as I know, you need to create guild first, using something like:

const guild = client.guilds.cache.get("YOUR_GUILD_ID");

And than, you need to use it:

client.on('message', msg => {
let guild = message.guild;
  if (msg.content === '.lock') {
msg.channel.send('Successfully locked the channel.');
if(!message.member.roles.some(r=>["👮︱Moderator", "🔱 ︱Trial Administrator"].includes(r.name))) return message.channel.send(`You dont have the moderator role!`)
message.channel.overwritePermissions(role,{ 'SEND_MESSAGES': false })
  }
});

P.S. Don't have access to IDE right now, so don't know if it's work

Also, the better way to let roles use command is:

let allowedRole = message.guild.roles.find("name", "Staff");
if (message.member.roles.has(allowedRole.id) {
    // allowed access to command
} else { //aka members who arent staff 
   // not allowed access
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda