-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
65 lines (45 loc) · 1.73 KB
/
index.js
File metadata and controls
65 lines (45 loc) · 1.73 KB
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
// 378225757200
require('dotenv').config()
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const { Guild } = require('discord.js');
const bodyParser = require('body-parser');
const rest = new REST({ version: '9' }).setToken(process.env.DISCORD_BOT_TOKEN);
const { Client, Intents } = require('discord.js');
const allIntents = new Intents(32767);
const client = new Client({ intents: [ allIntents ]});
var express = require('express')
var app = express()
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.get('/', function (req, res) {
console.log("===================================");
res.status(200).send("helloworld");
})
app.post('/adduser', async function (req, res) {
// 0 - Get the access_token, uid from the body
// 1- Find Guild from Client
// MAKE SURE USER IS MEMBER OF GUILD -> Add them to Server
// 2- FIND THE MEMBER => through the UID
// 3- Guild Add Role to Member
// 4- Done
// console.log(client)
const userID = req.body.userID;
const serverID = '858440479469469716';
const hack4pan2022Role = '926967736209379328';
// Accesstoken from the request & UID
const user = new Discord.User(client, data);
const guild = await client.guilds.cache.get(serverID);
let role = await guild.roles.cache.find(r => r.id === hack4pan2022Role);
const options = {
accessToken: "",
roles = [role]
}
await guild.addMember(user);
let member = await guild.members.cache.get(userID);
member.roles.add(role);
return res.status(201).send({data: "Role added"});
})
client.login(process.env.DISCORD_BOT_TOKEN);
app.listen(8081)
console.log("RUNNING ON 8081")