Skip to content

Instantly share code, notes, and snippets.

@gitscosh
Forked from DrewCaliber/Info.txt
Created January 5, 2022 00:27
Show Gist options
  • Save gitscosh/e7e1e9b7f155825670710064f675e4ac to your computer and use it in GitHub Desktop.
Save gitscosh/e7e1e9b7f155825670710064f675e4ac to your computer and use it in GitHub Desktop.
Main index for TheAlcoveBot in Discord.js v12
{
"prefix": "?",
"token": "PASTE YOUR DISCORD BOT TOKEN HERE",
"failures": "ChannelIDForLoggingFailedTIckets",
"opened": "channelIDForLoggingOpenedTicketsAndCount",
"closed": "channelIDForLoggingClosedTicketsAndWhoClosedThem",
"staffRoleID": "IDForTheStaffRole Can Be Seperate From Mod Or Admin Role. Should Have No Actual Perms. Please Only Give Perms To Actual Mod Roles. This is for the bot to know who can close tickets",
"requestChannel": "IDForRequestChannel",
"offerChannel" : "IDForAnOfferChannelIfApplicable"
}
// eslint-disable-next-line no-unused-vars
const config = require('./config.json');
const fs = require('fs');
// const ticketCountNumber = require('./ticketcount.json');
// eslint-disable-next-line no-unused-vars
const { prefix, token, closed, opened, failures, staffRoleID, requestChannel, offerChannel } = require ('./config.json');
const Discord = require('discord.js');
const client = new Discord.Client();
// #region EMBEDs
const failEmbedOffer = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle('Offer Removed')
.setDescription('Please re-read the pinned message on how to use the offers channel and take close note of the formatting! Pinned messages can be found in the top right of the channel with a thumbtack icon. Click that to see pinned messages. If you received this message in error, please @Staff in the #❓-𝐒upport-𝐂hannel')
.setThumbnail('https://i.ibb.co/Q9ywgQM/external-content-duckduckgo.png')
.setImage('https://i.ibb.co/LnJb5Vv/Pins.png')
.setTimestamp()
.setFooter('I am a bot. This is an automated message.');
const failEmbed = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle('Request Removed')
.setDescription('Please re-read the pinned message on how to use the requests channel and take close note of the formatting! Pinned messages can be found in the top right of the channel with a thumbtack icon. Click that to see pinned messages. If you received this message in error, please @Staff in the #❓-𝐒upport-𝐂hannel')
.setThumbnail('https://i.ibb.co/Q9ywgQM/external-content-duckduckgo.png')
.setImage('https://i.ibb.co/LnJb5Vv/Pins.png')
.setTimestamp()
.setFooter('I am a bot. This is an automated message.');
client.once('ready', () => {
console.log('Ready!');
});
// #endregion EMBED
// #region AutoWipe
//More SPaghetti code that could help auto wipe a channel in Discord Couldn't get it working.
//async function clearAllMessagesByCloning(channel) {
// Clone channel
// const newChannel = await channel.clone()
// console.log(newChannel.id) // Do with this new channel ID what you want
//
// Delete old channel
// channel.delete()
//}
//#endregion
// #region Request Event Handler
client.on('message', message => {
const wordCount = message.content.split(' ');
let ticketCountNumberPull = fs.readFileSync('./ticketcount.json', 'utf8');
if (message.author.bot && message.channel.id === requestChannel) {
message.delete();
}
//Change all the emoji IDs to ones you want. Or // them out completely
if (message.content.startsWith `-` && message.channel.id === requestChannel && wordCount.length >= 3) {
message.react ('PASTE YOUR EMOJI ID HERE');
message.react ('PASTE YOUR EMOJI ID HERE');
message.react ('PASTE YOUR EMOJI ID HERE')
client.channels.cache.get(opened).send('Ticket opened by ' + message.author.toString() + ' Request#' + ticketCountNumberPull);
}
else if (message.channel.id === requestChannel) {
if (message.author.bot) return;
message.delete();
message.author.send(failEmbed);
message.channel.send;
client.channels.cache.get(failures).send('Ticket attempt failed by ' + message.author.toString() + ' Message Contents: ```' + message.content + '```');
}
});
client.on('messageReactionAdd', async (reaction, user) => {
if (user.bot) return;
if (reaction.emoji.id === 'PASTE YOUR EMOJI ID HERE' && user.id === reaction.message.author.id || await reaction.message.guild.members.fetch(user).then((userCheck) => userCheck.roles.cache.has(staffRoleID)) && reaction.emoji.id === 'PASTE YOUR EMOJI ID HERE' && reaction.message.channel.id === requestChannel) {
reaction.message.delete();
client.channels.cache.get(closed).send('Ticket opened by ' + reaction.message.author.toString() + ' completed by ' + user.toString());
}
});
// #endregion Request Event Handler
// #region Offer Event Handler
client.on('message', message => {
const wordCount = message.content.split(' ');
if (message.author.bot && message.channel.id === offerChannel) message.delete();
if (message.content.startsWith `-` && message.channel.id === offerChannel && wordCount.length >= 2) {
message.react ('I WANT WHATS ABOVE TYPE EMOJI LIKE A POINT UP');
}
else if (message.channel.id === offerChannel) {
if (message.author.bot) return;
message.delete();
message.author.send(failEmbedOffer);
// message.channel.send;
}
});
client.on('messageReactionAdd', async (reaction, user) => {
if (user.bot) return;
if (reaction.emoji.name === 'I WANT WHATS ABOVE TYPE EMOJI LIKE A POINT UP' && reaction.message.channel.id === offerChannel) {
let message = await reaction.message.author.send(user.tag + ' has reacted to ' + reaction.message.content + ' | Click here to open DMs: <https://discordapp.com/users/' + user.id + '>');
message.react ('PASTE A PUBLIC CLOSE EMOJI HERE');
}
});
client.on('messageReactionAdd', async (reaction, user) => {
if (user.bot) return;
if (reaction.emoji.name === 'PASTE A PUCLIC CLOSE EOMJI HERE' && reaction.message.channel.type === 'dm') {
reaction.message.delete();
}
});
// #endregion
// #region Offer First Post Handler
client.on('message', async message => {
let gasChamber = message.user.id
if (message.content.startsWith `-` && message.channel.id === offerChannel && wordCount.length >= 2 && await nameListCheck(gasChamber)) {
message.react ('GET THE PUBLIC EMOJI ID OR JUST PASTE EMOJI HERE DIRECTLY');
}
else if (message.channel.id === offerChannel) {
if (message.author.bot) return;
}
});
// #endregion
//YOU WILL NEED TO COMPLETELY REWORK THE EMBEDS TO FIT YOUR NEEDS. MANY EXAMPLES PROVIDED
// #region Helper Commands Handler
client.on('message', message => {
const mentioned = message.mentions.users.first();
const supportChanEmbed = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle('Please check out the Request Channel')
.setDescription(`Check here first <#871908141397344276> \n Not there? Make a request here: <#869078419319705632>`)
.setTimestamp()
const offerThisEmbed = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle('Please check out the I-Have-This Channel')
.setDescription(`All offers post here: \n <#871908141397344276>`)
.setTimestamp()
const pleaseReadThePinsEmbed = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle('Please read the pins located at the top of every channel!')
.setDescription(`Instructions Here: \n <#916102132900454411>`)
.setImage('https://i.ibb.co/wrdmP6v/Pins.png')
.setTimestamp()
const ruleEmbed = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle('Please read the rules for the Discord!')
.setDescription(`Click Here: \n <#860475696878452737>`)
.setTimestamp()
// CHANGE THE COMMANDS TO FIT YOUR NEEDS
if (message.content.startsWith(prefix + 'requests')) {
message.channel.send(`${mentioned}`, supportChanEmbed);
}
else if (message.content.startsWith(prefix + 'h')) {
message.channel.send(`${mentioned}`, offerThisEmbed);
}
else if (message.content.startsWith(prefix + 'pins')) {
message.channel.send(`${mentioned}`, pleaseReadThePinsEmbed);
}
else if (message.content.startsWith(prefix + 'rule')) {
message.channel.send(`${mentioned}`, ruleEmbed);
}
//Broken spaghetti code. Has the potential to dupe a channel, but the ID would need to be updated in the config.json
// else if (message.content.startsWith(prefix + 'nuke')) {
// async function clearAllMessagesByCloning(channel) {
// // Clone channel
// const newChannel = await channel.clone()
// console.log(newChannel.ID) // Do with this new channel ID what you want
// // Delete old channel
// channel.delete()
// }
// }
else {
return;
}
});
// #endregion
// #region TICKET COUNTER
client.on('message', message => {
if (message.author.bot && message.channel.id === opened) {
let ticketCountNumber = fs.readFileSync('./ticketcount.json', 'utf8');
let ticketCountNumberNew = parseInt(ticketCountNumber) + 1;
const toBeWritten = JSON.stringify(ticketCountNumberNew);
try {
fs.writeFileSync('./ticketcount.json', toBeWritten, 'utf8');
}
catch (err) {
console.error(err);
}
}
});
// #endregion TICKET COUNTER
// #region Old Reaction Fectcher Works for DM after restart but it take about a day
client.on('raw', packet => {
if (!['MESSAGE_REACTION_ADD', 'MESSAGE_REACTION_REMOVE'].includes(packet.t)) return;
const channel = client.channels.cache.get(packet.d.channel_id);
if (channel.messages.cache.has(packet.d.message_id)) return;
channel.messages.fetch(packet.d.message_id).then(message => {
const emoji = packet.d.emoji.id ? `${packet.d.emoji.name}:${packet.d.emoji.id}` : packet.d.emoji.name;
const reaction = message.reactions.cache.get(emoji);
if (reaction) reaction.users.cache.set(packet.d.user_id, client.users.cache.get(packet.d.user_id));
if (packet.t === 'MESSAGE_REACTION_ADD') {
client.emit('messageReactionAdd', reaction, client.users.cache.get(packet.d.user_id));
}
if (packet.t === 'MESSAGE_REACTION_REMOVE') {
client.emit('messageReactionRemove', reaction, client.users.cache.get(packet.d.user_id));
}
});
});
client.login(token);
// #endregion
The following is to help with setting up the bot. I know, a ton of things could have been writtin into the config.json. But this bot was designed basically from scratch by a complete newb fueled by redbull. So get over it.
prefix - The designated lead symbol to start every command with.
Go to https://discord.com/developers/applications login and create and follow these steps: https://www.writebots.com/discord-bot-token/.
token - Paste your bots Discord token between the qoutations
failures - Paste a channel ID that you want the logs for failed tickets to show up in
opened - Paste a channel ID that you want to log tickets being opened and the count
closed - Paste a channel ID that you want to log tickets being closed and by who
staffRoleID - Create a staff role in your discord. Make sure it is elevated just below moderator in Discord's permissions. This role is for people you want to be able to close requests. I recomend disabling the ability for mods to assign roles as well. This prevents alts and spam abuse. You need the ID for the role
requestChannel - Channel channel that the bot will use to create a user ticket. With small modification it can delete the message instantly posted by the author and send it in the mod chat. Intended use is for a self serve or community style help system
offerChannel - Channel ID for the channel that handles the offer of services
Start of index.js changes needed.
On Line 138 of index.js after message.react ( There is a place to paste a public emoji ID or directly paste the emoji there if possible. To get a public ID type this into a public channel. \:EmojiNameHere: and it will paste something like this <:appiejuice:87379282970366969696>
On Line 152 of index.js are all the embeds, these will most likely need to be completely changed. Or // our of existance.
On Line 185 of index.js are all the usable commands. These can be changed and most likely will need to be to suit your needs.
You will need an emoji for closing messages on lines 118, 124, 139 of index.js
You will need an emoji that points upward or get creative on 104, 116 of index.js
Both could be added to the config.json if I had time.
on lines 67,68, and 69 the bot cna react with up to 3 emoji IDs. // out ones if you don't need them, and more lines if you want it more complex.
At very start and to the far right end of Line 87, there are
As far as I know, everything that needs to be revised was notated. Feel free to dig through the code and tell me what I missed.
Drew Caliber#0420
This bot served us well over at TheAclove. 22619 Requests completed successfully. And 10s of 1000s more before we started tracking it. Thank you all! <3
echo
node index.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment