Polarcraft/discord-bot/routes/User.js

28 lines
767 B
JavaScript
Raw Normal View History

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