【问题标题】:Send message to certain channels in certain time在特定时间向特定频道发送消息
【发布时间】:2018-06-15 20:53:17
【问题描述】:

这是我迄今为止尝试过的。

bot.on('ready', () => {
    const moment = require('moment');
    const CronJob = require('cron').CronJob;

    var job = new CronJob({
        // cronTime: '00 03 00 * * 1-7', // 00:03:00
        cronTime: '* * * * *', //every minute
        onTick: function() {
            console.log(moment.tz('Europe/London').format('HH:mm:ss'))
            createShop()
        },
        start: false,
        timeZone: 'Europe/London'
    });
    job.start();

    function sss() {
        const embed = new Discord.RichEmbed()
        .setColor(0x8644ba)
        .setDescription('test')
        bot.channels.find('topic', 'test').send(embed)
    }
});

但机器人仅在一个公会中发送消息,即使我有 3 个带有频道的公会有“测试”主题

【问题讨论】:

  • 那么你有不止一个频道的主题是'test'?

标签: javascript node.js discord.js


【解决方案1】:

您只会获得一个频道,因为Collection.find() 只会返回第一个频道。要全部获取,请使用Collection.findAll()

这是一个例子:

function sss() {
  const embed = new Discord.RichEmbed()
    .setColor(0x8644ba)
    .setDescription('test');
  let results = bot.channels.findAll('topic', 'test'); //returns an array
  for (let channel of results) channel.send(embed);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-07-02
    • 2021-08-21
    • 2020-04-04
    • 2021-09-30
    • 2019-09-03
    • 2018-12-09
    • 2022-01-08
    相关资源
    最近更新 更多