-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
118 lines (111 loc) · 2.98 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
require("dotenv").config();
const {
Client,
IntentsBitField,
ApplicationCommandOptionType,
PermissionFlagsBits,
} = require("discord.js");
TOKEN = process.env.DISCORD_TOKEN;
const client = new Client({
intents: [
IntentsBitField.Flags.Guilds,
IntentsBitField.Flags.GuildMembers,
IntentsBitField.Flags.GuildMessages,
IntentsBitField.Flags.MessageContent,
],
});
client.login(TOKEN);
const commands = [
{
name: "hello",
description: "Replies to this command",
options: [],
},
{
name: "yt",
description: "Replies with a youtube channel",
options: [],
},
{
name: "clear",
description: "Deletes Messages",
options: [
{
name: "num_of_messages",
description: "Enter the number of messages to be deleted",
type: ApplicationCommandOptionType.Number,
required: true,
},
],
},
{
name: "kick",
description: "Kicks a member",
options: [
{
name: "user",
description: "Mention the user to be kicked",
type: ApplicationCommandOptionType.User,
required: true,
},
],
permissionsRequired: [PermissionFlagsBits.KickMembers],
},
{
name: "ban",
description: "Bans a member",
options: [
{
name: "user",
description: "Mention the user to be banned",
type: ApplicationCommandOptionType.User,
required: true,
},
],
permissionsRequired: [PermissionFlagsBits.BanMembers],
},
];
client.on("ready", async () => {
console.log("Hello bot is online!");
let server = await client.guilds.fetch("1143066380791455816");
let applicationCommands = await server.commands;
for (let index in commands) {
let command = commands[index];
await applicationCommands.create(command);
}
});
client.on("interactionCreate", async (interaction) => {
if (interaction.commandName == "hello") {
interaction.reply({ content: "Hai", ephemeral: true });
}
if (interaction.commandName == "yt") {
interaction.reply({
content: "https://www.youtube.com/channel/UCEOHwjMTAqy0LI-lQ2Ag3tA",
ephemeral: true,
});
}
if (interaction.commandName == "clear") {
const option = interaction.options.get("num_of_messages").value;
await interaction.channel.bulkDelete(option);
interaction.reply({
content: `Deleted ${option} messages`,
ephemeral: true,
});
}
if (interaction.commandName == "kick") {
await interaction.deferReply();
const option = interaction.options.get("user").value;
const user = await interaction.guild.members.fetch(option);
user.kick();
interaction.editReply({ content: `${user} have been kicked` });
}
if (interaction.commandName == "ban") {
await interaction.deferReply();
const option = interaction.options.get("user").value;
const user = await interaction.guild.members.fetch(option);
user.ban();
interaction.editReply({
content: `${user} have been banned by ${interaction.user}`,
});
}
});