added some new commands

- rename
- close
- delete
This commit is contained in:
DJj123dj
2022-05-02 12:41:15 +02:00
parent 8e7a98b810
commit 07de112f32
8 changed files with 263 additions and 31 deletions
+64
View File
@@ -0,0 +1,64 @@
const discord = require('discord.js')
const bot = require('../index')
const client = bot.client
const config = bot.config
module.exports = () => {
client.on("messageCreate",msg => {
if (!msg.content.startsWith(config.prefix+"close")) return
msg.channel.messages.fetchPinned().then(msglist => {
var firstmsg = msglist.last()
if (firstmsg == undefined || firstmsg.author.id != client.user.id){
msg.channel.send({content:"You are not in a ticket!"})
return
}
const closebutton = new discord.MessageActionRow()
.addComponents([
new discord.MessageButton()
.setCustomId("closeTicketTrue1")
.setDisabled(false)
.setStyle("SECONDARY")
.setEmoji("🔒")
])
msg.channel.send({content:"**Click on the button below to close this ticket!**",components:[closebutton]})
console.log("[system] closed a ticket via command")
})
})
client.on("interactionCreate",(interaction) => {
if (!interaction.isCommand()) return
if (interaction.commandName != "close") return
interaction.channel.messages.fetchPinned().then(msglist => {
var firstmsg = msglist.last()
if (firstmsg == undefined || firstmsg.author.id != client.user.id){
interaction.reply({content:"You are not in a ticket!"})
return
}
const closebutton = new discord.MessageActionRow()
.addComponents([
new discord.MessageButton()
.setCustomId("closeTicketTrue1")
.setDisabled(false)
.setStyle("SECONDARY")
.setEmoji("🔒")
])
interaction.reply({content:"**Click on the button below to close this ticket!**",components:[closebutton]})
console.log("[system] closed a ticket via command")
})
})
}
+64
View File
@@ -0,0 +1,64 @@
const discord = require('discord.js')
const bot = require('../index')
const client = bot.client
const config = bot.config
module.exports = () => {
client.on("messageCreate",msg => {
if (!msg.content.startsWith(config.prefix+"delete")) return
msg.channel.messages.fetchPinned().then(msglist => {
var firstmsg = msglist.last()
if (firstmsg == undefined || firstmsg.author.id != client.user.id){
msg.channel.send({content:"You are not in a ticket!"})
return
}
const closebutton = new discord.MessageActionRow()
.addComponents([
new discord.MessageButton()
.setCustomId("deleteTicketTrue")
.setDisabled(false)
.setStyle("SECONDARY")
.setEmoji("❌")
])
msg.channel.send({content:"**Click on the button below to delete this ticket!**",components:[closebutton]})
console.log("[system] deleted a ticket via command")
})
})
client.on("interactionCreate",(interaction) => {
if (!interaction.isCommand()) return
if (interaction.commandName != "delete") return
interaction.channel.messages.fetchPinned().then(msglist => {
var firstmsg = msglist.last()
if (firstmsg == undefined || firstmsg.author.id != client.user.id){
interaction.reply({content:"You are not in a ticket!"})
return
}
const closebutton = new discord.MessageActionRow()
.addComponents([
new discord.MessageButton()
.setCustomId("deleteTicketTrue")
.setDisabled(false)
.setStyle("SECONDARY")
.setEmoji("❌")
])
interaction.reply({content:"**Click on the button below to delete this ticket!**",components:[closebutton]})
console.log("[system] deleted a ticket via command")
})
})
}
-27
View File
@@ -8,33 +8,6 @@ const config = bot.config
//============================= //=============================
module.exports = () => { module.exports = () => {
client.on("messageCreate",msg => {
var args = msg.content.split(" ")
if (args[0] == config.prefix+"ticket" && args[1] == "close"){
msg.channel.messages.fetchPinned().then(msglist => {
var firstmsg = msglist.last()
if (firstmsg == undefined){
msg.channel.send({content:"I didn't find the close button!"})
}
if (firstmsg.author.id != client.user.id){
msg.channel.send({content:"You are not in a ticket!"})
return
}
var CloseMsg = new discord.MessageEmbed()
.setColor(config.main_color)
.setDescription("Click [here]("+firstmsg.url+") to close this ticket.")
.setTitle("Close this ticket:")
msg.channel.send({embeds:[CloseMsg]})
if (config.logs){console.log("[command] "+config.prefix+"ticket close (user:"+msg.author.username+")")}
})
}
})
client.on("messageCreate",msg => { client.on("messageCreate",msg => {
var args = msg.content.split(" ") var args = msg.content.split(" ")
if (args[0] == config.prefix+"ticket" && args[1] == "rename"){ if (args[0] == config.prefix+"ticket" && args[1] == "rename"){
+1 -1
View File
@@ -18,7 +18,7 @@ module.exports = () => {
if (!msg.content.startsWith(config.prefix)) return if (!msg.content.startsWith(config.prefix)) return
var args = msg.content.split(config.prefix) var args = msg.content.split(config.prefix)
if (!args[1].startsWith("close") && !args[1].startsWith("delete") && !args[1].startsWith("remove") && !args[1].startsWith("add") && !args[1].startsWith("msg") && !args[1].startsWith("remove") && !args[1].startsWith("msg")){ if (!args[1].startsWith("close") && !args[1].startsWith("delete") && !args[1].startsWith("remove") && !args[1].startsWith("add") && !args[1].startsWith("msg") && !args[1].startsWith("remove") && !args[1].startsWith("rename")){
msg.channel.send({embeds:[helpEmbed]}) msg.channel.send({embeds:[helpEmbed]})
if (config.logs){console.log("[command] "+config.prefix+"ticket help (user:"+msg.author.username+")")} if (config.logs){console.log("[command] "+config.prefix+"ticket help (user:"+msg.author.username+")")}
+81
View File
@@ -0,0 +1,81 @@
const discord = require('discord.js')
const bot = require('../index')
const client = bot.client
const config = bot.config
module.exports = () => {
client.on("messageCreate",msg => {
if (!msg.content.startsWith(config.prefix+"rename")) return
msg.channel.messages.fetchPinned().then(msglist => {
var firstmsg = msglist.last()
if (firstmsg == undefined || firstmsg.author.id != client.user.id){
msg.channel.send({content:"You are not in a ticket!"})
return
}
if (!msg.member.permissions.has("MANAGE_CHANNELS") && !msg.member.permissions.has("ADMINISTRATOR")){
return msg.channel.send({content:"You have no permissions to change the channel name!\nYou need the `ADMINISTRATOR` or `MANAGE_CHANNELS` permission"})
}
var newname = msg.content.split(config.prefix+"rename")[1].substring(1)
var name = msg.channel.name
var prefix = ""
const tickets = config.options
tickets.forEach((ticket) => {
if (name.startsWith(ticket.channelprefix)){
prefix = ticket.channelprefix
}
})
if (!prefix) prefix = "noprefix-"
msg.channel.setName(prefix+newname)
msg.channel.send({content:"**The name is changed!**\nWarning: you can only change the channel name 2 times per minute! (this is due discord rate limits)"})
console.log("[system] renamed a ticket via command")
})
})
client.on("interactionCreate",(interaction) => {
if (!interaction.isCommand()) return
if (interaction.commandName != "rename") return
interaction.channel.messages.fetchPinned().then(msglist => {
var firstmsg = msglist.last()
if (firstmsg == undefined || firstmsg.author.id != client.user.id){
interaction.reply({content:"You are not in a ticket!"})
return
}
const member = client.guilds.cache.find(g => g.id == interaction.guild.id).members.cache.find(m => m.id == interaction.member.id)
if (!member.permissions.has("MANAGE_CHANNELS") && !member.permissions.has("ADMINISTRATOR")){
return interaction.reply({content:"You have no permissions to change the channel name!\nYou need the `ADMINISTRATOR` or `MANAGE_CHANNELS` permission"})
}
var newname = interaction.options.getString("name")
var name = interaction.channel.name
var prefix = ""
const tickets = config.options
tickets.forEach((ticket) => {
if (name.startsWith(ticket.channelprefix)){
prefix = ticket.channelprefix
}
})
if (!prefix) prefix = "noprefix-"
interaction.channel.setName(prefix+newname)
interaction.reply({content:"**The name is changed!**\nWarning: you can only change the channel name 2 times per minute! (this is due discord rate limits)"})
console.log("[system] renamed a ticket via command")
})
})
}
+30
View File
@@ -126,6 +126,36 @@ module.exports = () => {
require("./ticketCloser").closeTicket(interaction,prefix,"close") require("./ticketCloser").closeTicket(interaction,prefix,"close")
}) })
client.on("interactionCreate",interaction => {
if (!interaction.isButton()) return
if (interaction.customId != "closeTicketTrue1") return
interaction.deferUpdate()
const closedButtonDisabled = new discord.MessageActionRow()
.addComponents([
new discord.MessageButton()
.setCustomId("closeTicketTrue1")
.setDisabled(true)
.setStyle("SECONDARY")
.setEmoji("🔒")
])
interaction.message.edit({components:[closedButtonDisabled]})
/**
* @type {String}
*/
const name = interaction.channel.name
var prefix = ""
const tickets = config.options
tickets.forEach((ticket) => {
if (name.startsWith(ticket.channelprefix)){
prefix = ticket.channelprefix
}
})
require("./ticketCloser").closeTicket(interaction,prefix,"close")
})
//NORMAL DELETE //NORMAL DELETE
client.on("interactionCreate",interaction => { client.on("interactionCreate",interaction => {
+20 -3
View File
@@ -13,7 +13,6 @@ module.exports = async () => {
var choices = [] var choices = []
ids.forEach((id) => { ids.forEach((id) => {
const option = getoptions.getOptionsById(id) const option = getoptions.getOptionsById(id)
console.log(option.id)
choices.push({name:option.name,value:option.id}) choices.push({name:option.name,value:option.id})
}) })
@@ -26,8 +25,8 @@ module.exports = async () => {
var readystats = 0 var readystats = 0
setInterval(() => { setInterval(() => {
console.log("[status] there are "+chalk.blue(readystats+" out of 8")+" commands ready! (this can take some time)") console.log("[status] there are "+chalk.blue(readystats+" out of 9")+" commands ready! (this can take some time)")
if (readystats >= 8){ if (readystats >= 9){
console.log(chalk.green("ready!")) console.log(chalk.green("ready!"))
console.log(chalk.blue("you can now start the bot with 'npm start'!")) console.log(chalk.blue("you can now start the bot with 'npm start'!"))
process.exit(1) process.exit(1)
@@ -160,4 +159,22 @@ module.exports = async () => {
readystats++ readystats++
}) })
//rename
client.application.commands.create({
name:"rename",
description:"Rename this ticket.",
defaultPermission:true,
type:"CHAT_INPUT",
options:[
{
type:"STRING",
name:"name",
description:"The new name (without prefix).",
required:true
}
]
},sid).then(() => {
readystats++
})
} }
+3
View File
@@ -51,6 +51,9 @@ if (process.argv[2] != "slash"){
//commands //commands
require('./commands/ticket')() require('./commands/ticket')()
require("./commands/help")() require("./commands/help")()
require("./commands/close")()
require("./commands/delete")()
require("./commands/rename")()
//core //core
require('./core/ticketOpener')() require('./core/ticketOpener')()