Reputation: 37
I would like to know why message.guild.channels.cache is not a function Of course there is a sequel but I show that the main one. If you want the rest, just ask me! ;-; I seriously need your help, you reading my post!
client.on("ready",()=>{
console.log("TicketBot is online!");
client.user.setActivity("type !ticket help to get started");
});
client.on("message",async message=>{
if(message.author.bot||message.type=="dm")return;
var arg = message.content.toLowerCase().split(" ");
if(arg[0]!='!ticket')return;
if(!message.guild.me.hasPermission("MANAGE_CHANNELS")||!message.guild.me.hasPermission("MANAGE_ROLES")){
message.channel.send("Not enough permissions I require the `MANAGE_CHANNELS` and `MANAGE_ROLES` permission!");
return;
}
let TicketCategory = message.guild.channels.cache.find(channel=>channel.name==="Open Tickets");
if(TicketCategory==null){
await message.guild.channels.create('Open Tickets', {
type: 'category',
permissionOverwrites: [{
id: message.guild.id,
deny: ['READ_MESSAGES']
}]
})
.then(t=>TicketCategory=t)
.catch(console.error);
}
Upvotes: 0
Views: 1596
Reputation: 6645
client.on("message", async (message) => {
if (message.author.bot || message.channel.type == "dm") return false;
const args = message.content.toLowerCase().split(" ");
if (args[0] == "!ticket") {
if (!message.guild.me.hasPermission("MANAGE_CHANNELS") || !message.guild.me.hasPermission("MANAGE_ROLES")) return message.channel.send("Not enough permissions I require the `MANAGE_CHANNELS` and `MANAGE_ROLES` permission!");
const TicketCategory = message.guild.channels.cache.find(channel => channel.name == "Open Tickets");
if (!TicketCategory) {
message.guild.channels.create("Open Tickets", {
type: "category",
// READ_MESSAGES is not a valid permission flag in Discord JS v12.
// Use READ_MESSAGE_HISTORY or VIEW_CHANNEL.
permissionOverwrites: [{id: message.guild.roles.everyone, deny: ["READ_MESSAGE_HISTORY"]}]
}).catch(e => console.log(e));
}
}
});
Upvotes: 1