【问题标题】:How fetch all messages from a channel and send it randomly with a command ? (discord.js)如何从频道中获取所有消息并使用命令随机发送? (discord.js)
【发布时间】:2021-06-28 14:39:54
【问题描述】:

我是 JS 新手,我正在尝试从频道中获取消息以使用如下命令发送它们:

用户:.perle

bot : "来自特定频道的随机字符串"

这是我现在的代码:

    if (arg[0] === ".perle" && !msg.author.bot) {
    msg.channel.messages.fetch({around: "CHANNEL ID", limit: 30})
        .then(messages => {
        msg.channel.send(embedVariable);
    });

}

对不起,伙计们,我知道这很糟糕 x) 感谢您的帮助!

【问题讨论】:

    标签: discord.js fetch message send channel


    【解决方案1】:
    if (arg[0] === ".perle" && !message.author.bot) {
        perle();
        return;
    }
        async function perle() {
            const channel = client.channels.cache.get('710463736644763648');
            const messages = await channel.messages.fetch({ limit: 100 })
                let arr = messages.array();
                const random = Math.floor(Math.random() * messages.size);
                console.log(arr[random]);
                if (arr[random].content == "")
                    perle();
                message.channel.send(arr[random].content);
        }
    

    我成功了,希望对你有帮助

    【讨论】:

      猜你喜欢
      • 2021-05-17
      • 2020-10-02
      • 2020-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-24
      • 2021-03-24
      • 2019-05-29
      相关资源
      最近更新 更多