Files
discord.js/packages/discord.js/test/templateCreateGuild.js
2022-01-28 19:14:20 +01:00

28 lines
805 B
JavaScript

'use strict';
const { token } = require('./auth');
const { Client, GatewayIntentBits } = require('../src');
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages] });
client
.on('ready', () => console.log('ready'))
.on('messageCreate', async message => {
try {
const templates = await message.guild.fetchTemplates();
if (!templates.size) {
console.log('no templates');
} else {
const guild = await templates.first().createGuild('guild name');
console.log(`created guild with id ${guild.id}`);
await guild.delete();
console.log('deleted guild');
}
} catch (error) {
console.error(error);
} finally {
client.destroy();
}
})
.login(token)
.catch(console.error);