Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

380
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
ยฉ 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!