Polarcraft/discord-bot/routes/User.js

48 lines
1.3 KiB
JavaScript
Raw Normal View History

2023-05-11 19:46:59 +02:00
const express = require('express');
2023-05-27 12:02:33 +02:00
const index = require('../index');
2023-05-11 19:46:59 +02:00
const router = express.Router();
router.post('/changenickname', async (req, res) => {
const { nickname, discordId } = req.body;
2023-05-27 12:02:33 +02:00
if (!nickname || !discordId) return res.status(400).send({ error: 'Nickname en discordId zijn vereist' });
const nick = nickname.length > 32 ? nickname.slice(0, 32) : nickname;
2023-05-11 19:46:59 +02:00
try {
const guild = await index.client.guilds.fetch(process.env.GUILD_ID);
2023-05-27 12:02:33 +02:00
const member = await guild.members.fetch(discordId);
await member.edit({ nick: nick });
2023-05-11 19:46:59 +02:00
} catch (e) {
console.log(e);
2023-05-27 12:02:33 +02:00
return res.status(500).send({ error: 'Error tijds het veranderen van de nickname' });
2023-05-11 19:46:59 +02:00
}
res.send({ status: 'success' });
});
2023-05-27 12:02:33 +02:00
router.post('/ban', async (req, res) => {
const { discordId, reason } = req.body;
if (!reason || !discordId) return res.status(400).send({ error: 'Reason en discordId zijn vereist' });
try {
const guild = await index.client.guilds.fetch(process.env.GUILD_ID);
const member = await guild.members.fetch(discordId);
await member.ban({ deleteMessageSeconds: 24 * 3600, reason: reason });
} catch (e) {
console.log(e);
return res.status(500).send({ error: 'Error tijds het bannen van gebruiker' });
}
res.send({ status: 'success' });
});
2023-05-11 19:46:59 +02:00
module.exports = router;