Skip to content

Commit f751ce5

Browse files
committed
Slash commands
1 parent a0d08ba commit f751ce5

File tree

1,225 files changed

+148658
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,225 files changed

+148658
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
name: "ping",
3+
data: {
4+
name: "ping",
5+
description: "Comando di test"
6+
},
7+
execute(interaction) {
8+
var embed = new Discord.MessageEmbed()
9+
.setTitle("Pong")
10+
interaction.reply({ embeds: [embed], ephemeral: true })
11+
}
12+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
module.exports = {
2+
name: "kick",
3+
data: {
4+
name: "kick",
5+
description: "Espellere un utente",
6+
options: [
7+
{
8+
name: "user",
9+
description: "L'utente da espellere",
10+
type: "USER",
11+
required: true
12+
},
13+
{
14+
name: "reason",
15+
description: "Motivazione",
16+
type: "STRING",
17+
required: false
18+
}
19+
]
20+
},
21+
execute(interaction) {
22+
if (!interaction.member.permissions.has("KICK_MEMBERS")) {
23+
return interaction.reply({ content: "Non hai il permesso", ephemeral: true })
24+
}
25+
26+
var utente = interaction.options.getUser("user")
27+
var reason = interaction.options.getString("reason") || "Nessun motivo"
28+
29+
var member = interaction.guild.members.cache.get(utente.id)
30+
if (!member?.kickable) {
31+
return interaction.reply({ content: "Non posso kickare questo utente", ephemeral: true })
32+
}
33+
34+
member.kick()
35+
36+
var embed = new Discord.MessageEmbed()
37+
.setTitle("Utente kickato")
38+
.setThumbnail(utente.displayAvatarURL())
39+
.addField("User", utente.toString())
40+
.addField("Reason", reason)
41+
42+
interaction.reply({ embeds: [embed] })
43+
}
44+
}

Slash commands/index.js

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
global.Discord = require('discord.js');
2+
const client = new Discord.Client({
3+
intents: ["GUILDS", "GUILD_MEMBERS", "GUILD_MESSAGES", "GUILD_INTEGRATIONS"] //Importante - Inserire "GUILD_INTEGRATIONS" tra gli intents
4+
})
5+
6+
client.login("token");
7+
8+
client.on("ready", () => {
9+
console.log("ONLINE");
10+
11+
client.guilds.cache.forEach(guild => {
12+
guild.commands.create({
13+
name: "ping",
14+
description: "Comando di test"
15+
})
16+
17+
guild.commands.create({
18+
name: "kick",
19+
description: "Espellere un utente",
20+
options: [
21+
{
22+
name: "user",
23+
description: "L'utente da espellere",
24+
type: "USER",
25+
required: true
26+
},
27+
{
28+
name: "reason",
29+
description: "Motivazione",
30+
type: "STRING",
31+
required: false
32+
}
33+
]
34+
})
35+
})
36+
})
37+
38+
client.on("interactionCreate", interaction => {
39+
if (!interaction.isCommand()) return
40+
41+
if (interaction.commandName == "ping") {
42+
var embed = new Discord.MessageEmbed()
43+
.setTitle("Pong")
44+
interaction.reply({ embeds: [embed], ephemeral: true })
45+
}
46+
47+
if (interaction.commandName == "kick") {
48+
if (!interaction.member.permissions.has("KICK_MEMBERS")) {
49+
return interaction.reply({ content: "Non hai il permesso", ephemeral: true })
50+
}
51+
52+
var utente = interaction.options.getUser("user")
53+
var reason = interaction.options.getString("reason") || "Nessun motivo"
54+
55+
var member = interaction.guild.members.cache.get(utente.id)
56+
if (!member?.kickable) {
57+
return interaction.reply({ content: "Non posso kickare questo utente", ephemeral: true })
58+
}
59+
60+
member.kick()
61+
62+
var embed = new Discord.MessageEmbed()
63+
.setTitle("Utente kickato")
64+
.setThumbnail(utente.displayAvatarURL())
65+
.addField("User", utente.toString())
66+
.addField("Reason", reason)
67+
68+
interaction.reply({ embeds: [embed] })
69+
}
70+
})
71+
72+
73+
//Module export
74+
const fs = require("fs")
75+
client.commands = new Discord.Collection()
76+
77+
const commandsFolder = fs.readdirSync("./commands");
78+
for (const folder of commandsFolder) {
79+
const commandsFiles = fs.readdirSync(`./commands/${folder}`).filter(file => file.endsWith(".js"));
80+
for (const file of commandsFiles) {
81+
const command = require(`./commands/${folder}/${file}`);
82+
client.commands.set(command.name, command);
83+
}
84+
}
85+
86+
client.on("ready", () => {
87+
client.guilds.cache.forEach(guild => {
88+
client.commands.forEach(command => {
89+
guild.commands.create(command.data)
90+
})
91+
})
92+
})
93+
94+
client.on("interactionCreate", interaction => {
95+
if (!interaction.isCommand()) return
96+
97+
const command = client.commands.get(interaction.commandName)
98+
if (!command) return
99+
100+
command.execute(interaction)
101+
})

0 commit comments

Comments
 (0)