【问题标题】:Sending messages to other shards on Discord.js v12+在 Discord.js v12+ 上向其他分片发送消息
【发布时间】:2021-02-08 16:19:30
【问题描述】:

我正在尝试在我的 Discord 机器人中创建一个系统,它依赖于频道 ID 从频道 ID 的数据库中发布(例如:1234567891234)。

现在我的主要问题是能够通过 ID 发送到该频道,因为我正在使用 Discord.JS v12+ 和 ShardingManager。

我有这个基本代码,但不确定如何将该消息从一个通道中继到另一个通道,该通道位于与 OP 分片不同的分片上。

client.shard.broadcastEval(`
(async () => {
    const channel = await this.channels.cache.get('683353482748756047');
    if (channel) {
        channel.send("hi");
    }
})();
`);

我希望能够做到这一点,但有人建议我使用Discord's REST API 系统,但我对了解他们的 API 网络的每个部分并没有那么先进。

【问题讨论】:

    标签: javascript node.js discord discord.js


    【解决方案1】:

    原来我在不知不觉中回答了自己的问题;

    client.shard.broadcastEval(`
    (async () => {
        const channel = await this.channels.cache.get('${where.id}');
        if (channel) {
            channel.send("Hi");
        }
    })();
    `);
    

    现在我只需要添加嵌入功能就可以了。

    我希望这可以帮助任何使用 Discord.js 中的 ShardingManager 的人。

    【讨论】:

      猜你喜欢
      • 2021-11-02
      • 1970-01-01
      • 2020-12-10
      • 1970-01-01
      • 2020-11-06
      • 2023-03-20
      • 2016-08-09
      • 1970-01-01
      相关资源
      最近更新 更多