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

387
Visualizações
how do i use permission overwrites discord.js

it worked on my last bot but now the permission overwrites wont work on the new bot i looked at documentation on discord.js was just wandering if someone could help me out as im at a dead end

code:

module.exports = {
    name: 'ticket',
    description: "creates ticket",
    async execute(message, args, Discord){
        const channel = await message.guild.channels.create(`ticket: ${message.author.tag}`);
        channel.setParent('967965866035642408');

        channel.permissionOverwrites.edit(message.guild.id, {
            SEND_MESSAGES: false,
            VIEW_CHANNEL: false,
        });
        channel.permissionOverwrites.edit(message.author, {
            SEND_MESSAGES: true,
            VIEW_CHANNEL: true,
        });

        const reactionMessage = await channel.send('Thank you for contacting support!');

        try{

            await reactionMessage.react("🔒");
            await reactionMessage.react("⛔");

        }catch(err){
            channel.send('Error sending emojis!');
            throw err;
        }
        const collector = reactionMessage.createReactionCollector(
            (reaction, user) => message.guild.members.cache.find((member) => member.id === user.id).hasPermission("ADMINISTRATOR"),
            {dispose: true }
        );

        collector.on("collect", (reaction, user) => {
            switch (reaction.emoji.name) {
                case "🔒":
                    channel.permissionOverwrites.edit(message.author, { SEND_MESSAGES: false });
                    break;
                case "⛔":
                    channel.send('deleting this channel in 5 seconds');
                    setTimeout(() => channel.delete(), 5000);
                    break;
            }
        });

        message.channel.send(`we will be right with you! ${channel}`).then((msg) => {
            setTimeout(() => msg.delete(), 7000);
            setTimeout(() => message.delete(), 3000);
        }).catch((err) => {
            throw err;
        });
    }
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

So the first part of this would be the command, and I seperated the command from the reaction, just in case the bot reboots or there was ever an error with the collector, this code will survive a reboot. I also tested this on my bot and it works without issue.

Command.js file

module.exports = {
    name: 'ticket',
    description: "creates ticket",
    async execute(message, args, Discord) {
        const channel = await message.guild.channels.create(`ticket: ${message.author.tag}`, {
            parent: '967965866035642408',
            permissionOverwrites: [{
                id: message.guild.id,
                deny: [
                    'VIEW_CHANNEL',
                ],
            }, {
                id: message.author,
                allow: [
                    'VIEW_CHANNEL',
                    'SEND_MESSAGES',
                ],
            }],
        });

        const reactionMessage = await channel.send(`Thank you for contacting support! ${message.author}`);
        // message.author is important for later so make sure it stays in the message somehow.

        try {
            await reactionMessage.react("🔒");
            await reactionMessage.react("⛔");

        } catch (err) {
            channel.send('Error sending emojis!');
            throw err;
        }

        message.channel.send(`we will be right with you! ${channel}`).then((msg) => {
            setTimeout(() => msg.delete(), 7000);
            setTimeout(() => message.delete(), 3000);
        }).catch((err) => {
            throw err;
        });
    },
};

This section would go into your main bot.js file to catch the reaction add and it will auto remove reactions that are placed by members who are not admins

client.on('messageReactionAdd', async (messageReaction, user) => {
    if (user.bot) return;
    const message = await messageReaction.message.fetch(true);
    const channel = message.channel;
    const guild = client.guilds.cache.get(message.guildId);
    const member = guild.members.cache.get(user.id);

    if (channel.parent.id === '967965866035642408') {
        const regex = /\d+/g;
        const authorID = message.content.match(regex);
        const originalAuthor = client.users.cache.get(authorID[0]);
        if (!member.permissions.has("ADMINISTRATOR")) {
            message.reactions.cache.find(reaction => reaction.emoji.name == messageReaction.emoji.name).users.remove(member.user);
            return;
        } else {
            switch (messageReaction.emoji.name) {
            case "🔒":
                channel.permissionOverwrites.edit(originalAuthor, { SEND_MESSAGES: false });
                break;
            case "⛔":
                channel.send('deleting this channel in 5 seconds');
                setTimeout(() => channel.delete(), 5000);
                break;
            }
        }
    } else {
        return;
    }
});
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