Skip to content

Commit

Permalink
Merge pull request #3 from Arisamiga/RoleViewer
Browse files Browse the repository at this point in the history
Second Branch merge to Master
  • Loading branch information
Arisamiga authored Feb 18, 2022
2 parents 3683fa9 + 92fa7db commit f33b10e
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 353 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Discord-Ticket-Bot

### A Simple useful ticket bot for discord coded in Discord.js

<a href="https://github.com/Arisamiga/Discord-Ticket-Bot//issues">
Expand All @@ -7,7 +8,7 @@

[![CodeFactor](https://www.codefactor.io/repository/github/arisamiga/discord-ticket-bot/badge?s=ce8618765d3ec8b05264bac256588a4411f7712b)](https://www.codefactor.io/repository/github/arisamiga/discord-ticket-bot)

<img src= "https://i.imgur.com/bQhJm9q.jpg"> <img src="https://i.imgur.com/Zp2ke2P.jpg">
<img src= "https://i.imgur.com/XQi0yrC.jpg"> <img src="https://i.imgur.com/XBZZTA3.jpg">

## Installation
```
Expand All @@ -27,11 +28,13 @@ Change the following
"token": "(Enter Token here)",
"prefix": "(Enter Prefix Here)",
"owner": "(Enter id of Bot Owner)",
"Channelrole":"(Enter id of Viewing Role)",
"signup_color": "(Enter Hex Code for signup Embed Here)",
"signup_title": "(Enter Title for signup Embed Here)",
"answer_title": "(Enter Title for Answer Embed Here)",
"answer_color": "(Enter Hex Code for Answer Embed Here)",
"answer_description": "(Enter Answer Embed Description) (Use \n for breaking lines!)"
"answer_description": "(Enter Answer Embed Description) (Use \n for breaking lines!)",
"one_app": true (Pick either True = To allow only 1 ticket to exist at a time / False = To allow multiple ticket to exist at a time)
}
```
Expand Down
164 changes: 97 additions & 67 deletions commands/startapps.js
Original file line number Diff line number Diff line change
@@ -1,81 +1,111 @@
const Jsonfile = require('../config.json');
exports.run = async (client, message, args) => {
if (message.author.id !== Jsonfile.owner) return message.channel.send("Sorry but you cant use this command D:").then((msg) => {
exports.run = async (client, message) => {
if (message.author.id !== Jsonfile.owner) return message.channel.send("Sorry but you cant use this command D:").then((msg) => {
setTimeout(() => msg.delete(), 7000);
})
const signup = await message.channel.send({embed: {
color: Jsonfile.signup_color,
fields: [{
name: Jsonfile.signup_title,
value: "To create a ticket react with 📩"
}
],
timestamp: new Date(),
footer: {
icon_url: client.user.avatarURL()
})
const signupEmbed = {
color: Jsonfile.signup_color,
fields: [{
name: Jsonfile.signup_title,
value: "To create a ticket react with 📩"
}],
footer: {
icon_url: client.user.avatarURL()
}
}
const signup = await message.channel.send({
embeds: [signupEmbed]
});
await signup.react("📩")
const collector = signup.createReactionCollector(
(reaction, user) => message.guild.members.cache.find((member) => member.id === user.id), {
dispose: true
}
);
collector.on("collect", (reaction, user) => {
if (user.bot) return;
switch (reaction.emoji.name) {
case "📩":
let channelname = `ticket-${user.username}-${user.discriminator}`
channelname = channelname.replace(/\s/g, '-').toLowerCase()
if (message.guild.channels.cache.find(channel => channel.name === channelname) && Jsonfile.one_app) {
user.send(`You already have an ongoing ticket.`).catch(console.error);
reaction.users.remove(user.id)
return;
} else {
contining(user)
reaction.users.remove(user.id)
}
}
break;
}
})
async function contining(user) {
const channel = await message.guild.channels.create(`ticket: ${user.username + "-" + user.discriminator}`);

channel.permissionOverwrites.edit(message.guild.id, {
"SEND_MESSAGES": false,
"VIEW_CHANNEL": false,
});
await signup.react("📩")
const collector = signup.createReactionCollector(
(reaction, user) => message.guild.members.cache.find((member) => member.id === user.id),
{ dispose: true }
);
collector.on("collect", (reaction, user) => {
switch (reaction.emoji.name) {
case "📩":
contining(user)
break;
}
channel.permissionOverwrites.edit(user.id, {
"SEND_MESSAGES": true,
"VIEW_CHANNEL": true,
});
channel.permissionOverwrites.edit(Jsonfile.Channelrole, {
"SEND_MESSAGES": true,
"VIEW_CHANNEL": true,
})
async function contining(user){
const channel = await message.guild.channels.create(`ticket: ${user.username + "-" + user.discriminator}`);

channel.updateOverwrite(message.guild.id, {
"SEND_MESSAGE": false,
"VIEW_CHANNEL": false,
});
channel.updateOverwrite(user.id, {
"SEND_MESSAGE": true,
"VIEW_CHANNEL": true,
});

const reactionMessage = await channel.send({embed: {
color: Jsonfile.answer_color,
fields: [{
name: Jsonfile.answer_title,
value: Jsonfile.answer_description
}
],
timestamp: new Date(),
footer: {
icon_url: client.user.avatarURL()
}
}
})
await reactionMessage.react("🔒");
await reactionMessage.react("⛔");
const reactionMessageEmbed = {
color: Jsonfile.answer_color,
fields: [{
name: Jsonfile.answer_title,
value: Jsonfile.answer_description
}],
footer: {
icon_url: client.user.avatarURL()
}
}
const reactionMessage = await channel.send({
embeds: [reactionMessageEmbed]
})
await reactionMessage.react("🔒");
await reactionMessage.react("⛔");

const collector = reactionMessage.createReactionCollector(
(reaction, user) => message.guild.members.cache.find((member) => member.id === user.id).hasPermission("ADMINISTRATOR"),
{ dispose: true }
);
const collector = reactionMessage.createReactionCollector(
(reaction, user) => message.guild.members.cache.find((member) => member.id === user.id).permissions.has("ADMINISTRATOR") || message.guild.members.cache.find((member) => member.id === user.id).roles.cache.find(r => r.id === Jsonfile.Channelrole), {
dispose: true
}
);

collector.on("collect", (reaction, user) => {
switch (reaction.emoji.name) {
case "🔒":
channel.updateOverwrite(user.id, { "SEND_MESSAGES": false });
channel.send("Channel has been locked!");
collector.on("collect", (reaction, user) => {
if (user.bot) return;
switch (reaction.emoji.name) {
case "🔒":
if (message.guild.members.cache.find((member) => member.id === user.id).permissions.has("ADMINISTRATOR") || message.guild.members.cache.find((member) => member.id === user.id).roles.cache.find(r => r.id === Jsonfile.Channelrole)) {
channel.permissionOverwrites.edit(user.id, {
"SEND_MESSAGES": false
});
channel.send("Channel Locked 🔒");
break;
case "⛔":
if (message.guild.channels.cache.find(c => c.name.toLowerCase() === channel.name)) { //checks if there in an item in the channels collection that corresponds with the supplied parameters, returns a boolean
} else {
user.send("Only Staff can lock the channels")
reaction.users.remove(user.id)
break
}
case "⛔":
if (message.guild.channels.cache.find(c => c.name.toLowerCase() === channel.name)) {
if (message.guild.members.cache.find((member) => member.id === user.id).permissions.has("ADMINISTRATOR") || message.guild.members.cache.find((member) => member.id === user.id).roles.cache.find(r => r.id === Jsonfile.Channelrole)) {
setTimeout(() => channel.delete(), 5000);
channel.send("Deleting this channel in 5 seconds!");
return;
} else {
user.send("Only Staff can delete the channels")
reaction.users.remove(user.id)
break
}
}
break;
}
});
}
}
}
});
}
}
4 changes: 3 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
"token": "(Enter Token here)",
"prefix": "(Enter Prefix Here)",
"owner": "(Enter id of Bot Owner)",
"Channelrole":"(Enter id of Viewing Role)",
"signup_color": "(Enter Hex Code for signup Embed Here)",
"signup_title": "(Enter Title for signup Embed Here)",
"answer_title": "(Enter Title for Answer Embed Here)",
"answer_color": "(Enter Hex Code for Answer Embed Here)",
"answer_description": "(Enter Answer Embed Description) (Use \n for breaking lines!)"
"answer_description": "(Enter Answer Embed Description) (Use \n for breaking lines!)",
"one_app": true
}
File renamed without changes.
6 changes: 3 additions & 3 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const Discord = require('discord.js');
const client = new Discord.Client();
const {Collection, Intents, Client} = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES,Intents.FLAGS.GUILD_MESSAGE_REACTIONS] });
const fs = require('fs');
const token = require('./config.json');

Expand All @@ -18,7 +18,7 @@ fs.readdir("./events/", (err, files) => {
});
});

client.commands = new Discord.Collection();
client.commands = new Collection();

fs.readdir("./commands/", (err, files) => {
if (err) return console.error(err);
Expand Down
Loading

0 comments on commit f33b10e

Please sign in to comment.