Reputation: 21
I'm trying to create a channel with Discord.js using the message.guild.createChannel
function. But, I need to send a message on the server for the bot to do that. How can I do it at the bot startup ? I think I need to implement my code into the bot.on('ready', () => {
function, but I don't know how. Thanks !
This is my code:
var firstLog = false;
bot.on('message', msg => {
if (!firstLog) {
msg.guild.createChannel('raidprotect-logs', "text")
} firstLog = true;
});
Upvotes: 1
Views: 268
Reputation: 2722
You need use somethink like this if you want use it on message
var firstLog = false;
bot.on('message', msg => {
if (!firstLog) msg.guild.createChannel('new-general', { type: 'text' })
firstLog = true;
});
If you want you use it when bot start , you need get guild fist.
bot.on('ready', () => {
let myGuild = bot.guilds.get('GUILDID HERE')
myGuild.createChannel('new-general', { type: 'text' })
.then(console.log(“done”))
.catch(console.error);
});
Upvotes: 2
Reputation: 197
You're almost there. Here's how you do it
bot.on('ready', () => {
guild.createChannel('new-general', { type: 'text' })
.then(console.log)
.catch(console.error);
});
As they suggested here
You can find more help on Discord.js Official discord server
Upvotes: 0