-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsampleCode.js
46 lines (38 loc) · 1.07 KB
/
sampleCode.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
// Required libraries for repl.it
const Discord = require('discord.js')
const fetch = require('node-fetch');
const axios = require('axios');
// Required keys & tokens
const postman_API_key = 'your-postman-api-key';
const discord_bot_token = "your-discord-bot-token";
const bot = new Discord.Client();
const prefix = '!fn'
bot.on('ready', () => {
console.log("bot logged on")
})
bot.on('message', async msg => {
// Checks for !fn prefix and does nothing if not found
if(msg.content[0] + msg.content[1] + msg.content[2] !== prefix){
return
}
const args = msg.content.slice(prefix.length).trim().split(' ');
const command = args.shift().toLowerCase();
if (command === 'user') {
let name = "Ninja";
if(args[0]) {
name = args[0]
}
let user = {
"username": name
}
let url = `your-url-from-postman`;
let response = fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
"body": JSON.stringify(user)
});
}
})
bot.login(discord_bot_token);