-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
123 lines (90 loc) · 3.4 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
119
120
121
const fs = require('fs');
const { Client, Collection, Intents } = require('discord.js');
const { token } = require('./config.json');
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
client.commands = new Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.data.name, command);
}
client.once('ready', () => {
console.log('Ready!');
});
client.on('interactionCreate', async interaction => {
if (!interaction.isCommand()) return;
const command = client.commands.get(interaction.commandName);
if (!command) return;
try {
await command.execute(interaction);
} catch (error) {
console.error(error);
return interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
});
client.login(token);/*
client.on('interactionCreate', async interaction => {
if (!interaction.isCommand()) return;
const command = client.commands.get(interaction.commandName);
if (!command) return;
try {
await command.execute(interaction);
} catch (error) {
console.error(error);
return interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
});*/
/*
//writing a msg
client.on('interactionCreate', async interaction => {
if (!interaction.isCommand()) return;
const { commandName } = interaction;
if (commandName === 'ping') {
await interaction.reply('Hi User! Nice to meet u. 🤗🤗But dont u think instead of pinging me, u are supposed to study for exam ?😑😑 Go study LOSER 🙄');
} else if (commandName === 'server') {
await interaction.reply(`Server name: ${interaction.guild.name}\nTotal members: ${interaction.guild.memberCount}\n Server created at: ${interaction.guild.createdAt}\n Owner : ${interaction.fetchOwner}`);
} else if (commandName === 'user') {
await interaction.reply(`Your tag: ${interaction.user.tag}\nYour id: ${interaction.user.id}`);
}
});
client.login(token);
// writing an event handler:message
client.on('message', gotMessage);
function gotMessage(msg)
{
console.log(msg);
if(msg.content=='hi bot')
{
msg.reply('Hello mate,Nice to meet u 😀😀💗💗');
}
}
/*
//making a simple bot
const { Client, Intents } = require('discord.js'); //require func imports the discord.js module
const client = new Client({ intents: [Intents.FLAGS.GUILDS] }); // Client is js object that connects to dicord api to runt he bot
client.login('OTMxMTMwMDI1OTM0MTkyNjUw.Yd_8aQ.oQEMRflr4DIXDtKw8Pnz6jtrrZY'); // authenticate the bot with bot token
//to know when authentication is done, on()
//anonymous function type
client.on('ready', () => { //to handle event named ready
console.log(`Logged in as ${client.user.tag}! 💗💗`);
});
// another event handler. here its me
client.on('interactionCreate', async interaction => {
if (!interaction.isCommand()) return;
if (interaction.commandName === 'ping') {
await interaction.reply('Pong!');
}
});
client.on('message',gotMessage);
function gotMessage(msg)
{
console.log(msg.content);
if(msg.content ==='hi satwi')
{ msg.reply('Heyyy dear butterfly ❤💗💕');}
}
*/
// generally hardcoding the token directly iss a bad idea
/* olde way wont work
const Discord= require('discord.js');
const client =new Discord.Client();
*/