我正在尝试使用message.guild.createChannel函数使用Discord.js创建一个频道。但是,我需要在服务器上发送一条消息,机器人才能做到这一点。在机器人启动时该如何做?我想我需要将代码实现到bot.on('ready', () => {函数中,但是我不知道该怎么做。谢谢 !

这是我的代码:

var firstLog = false;

bot.on('message', msg => {
  if (!firstLog) {
    msg.guild.createChannel('raidprotect-logs', "text")
  } firstLog = true;
});

最佳答案

如果要在消息上使用它,则需要使用类似这样的东西

var firstLog = false;

bot.on('message', msg => {
  if (!firstLog) msg.guild.createChannel('new-general', { type: 'text' })
firstLog = true;
});

如果您想在机器人启动时使用它,则需要获得公会拳头。
bot.on('ready', () => {
    let myGuild = bot.guilds.get('GUILDID HERE')
   myGuild.createChannel('new-general', { type: 'text' })
        .then(console.log(“done”))
        .catch(console.error);
});

09-25 13:08