I have a problem with this error:
UnhandledPromiseRejectionWarning: TypeError [INVALID_TYPE]: Supplied parameter is not a User nor a Role.
I tried almost every single fix I know, tried to looking to api for discover what is wrong but I did not get any solution.
Here's the code:
const Discord = require('discord.js')
const { MessageEmbed } = require('discord.js');
const config = require('../../config.json');
module.exports = {
name: "new",
category: "tickets",
description: "Vytvorí nový ticket",
usage: "[príkaz | alias]",
run: async (client, message, args) => {
message.delete();
let [parent, support, supervisor] = [config.tickets.category, message.guild.roles.cache.get(config.tickets.roles.support), message.guild.roles.cache.get(config.tickets.roles.supervisor)];
let co = true;
function check() {
let channels = message.guild.channels.cache.filter(ch => ch.type === 'text' && ch.name.startsWith('ticket-'));
channels.forEach(channel => {
if(channel.topic.includes(message.author.id)) co = false;
});
}
check();
if(!co) {
let embed = new MessageEmbed().addField(':x: Error 404', 'Už máš otvorený ticket. Prosím ukonči ho predtým ako vytvoríš ďalší!').setColor('RED');
return message.channel.send({embed: embed});
}
let ticket = await message.guild.channels.create(`ticket-${message.author.username}`, 'text');
let ch = await message.guild.channels.cache.find(channel => channel.id === parent);
if(ch && ch.type === 'category') ticket.setParent(ch.id);
ticket.setTopic(message.author.id);
ticket.overwritePermissions([message.guild.roles.everyone, { SEND_MESSAGES: false, VIEW_CHANNEL: false, READ_MESSAGE_HISTORY: false }]);
ticket.overwritePermissions([message.author.id, { SEND_MESSAGES: true, VIEW_CHANNEL: true, READ_MESSAGE_HISTORY: true }]);
if(support) ticket.overwritePermissions([support.id, { SEND_MESSAGES: true, VIEW_CHANNEL: true, READ_MESSAGE_HISTORY: true }]);
if(supervisor) ticket.overwritePermissions([supervisor.id, { SEND_MESSAGES: true, VIEW_CHANNEL: true, READ_MESSAGE_HISTORY: true, MANAGE_MESSAGES: true }]);
let embed = new MessageEmbed().setColor('BLUE').setAuthor(`Vitaj ${message.author.tag}`, message.author.displayAvatarURL).setDescription(config.tickets.messages.welcome);
ticket.send({embed: embed});
embed = new MessageEmbed().setColor('GREEN').addField(`✅ Ticket Vytvorený`, `Úspešne vytvorený tvoj ticket <#${ticket.id}>`);
message.channel.send({embed: embed});
}
};
The thing is that this code does not overwrite the Permissions.
ticket.overwritePermissions([message.guild.roles.everyone, { SEND_MESSAGES: false, VIEW_CHANNEL: false, READ_MESSAGE_HISTORY: false }]);
ticket.overwritePermissions([message.author.id, { SEND_MESSAGES: true, VIEW_CHANNEL: true, READ_MESSAGE_HISTORY: true }]);
if(support) ticket.overwritePermissions([support.id, { SEND_MESSAGES: true, VIEW_CHANNEL: true, READ_MESSAGE_HISTORY: true }]);
if(supervisor) ticket.overwritePermissions([supervisor.id, { SEND_MESSAGES: true, VIEW_CHANNEL: true, READ_MESSAGE_HISTORY: true, MANAGE_MESSAGES: true }]);
Any help for this? Will be much appreciated.