Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

385
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda