【发布时间】:2021-11-29 16:14:24
【问题描述】:
如何在我的机器人所在的每个公会发送一条消息?不管是哪个频道,但我不知道如何编码。
我终于想出了这个主意:
client.guilds.cache.forEach(guild => {
const Embed = new discord.MessageEmbed();
const Channels = guild.channels.cache.map(channel => `${channel.id} | ${channel.name}`).join(", ")
Embed.setTitle(`Channels for ${guild.name}`);
Embed.setDescription(Channels);
message.channel.send(Embed);
});
但它不起作用。
我正在使用命令处理程序,因此必须使用module.exports:
module.exports = {
name: "informacja",
aliases: [],
description: "informacja",
async execute(message) {
client.guilds.cache.forEach(guild => {
const Embed = new discord.MessageEmbed();
const Channels = guild.channels.cache.map(channel => `${channel.id} | ${channel.name}`).join(", ")
Embed.setTitle(`Channels for ${guild.name}`);
Embed.setDescription(Channels);
message.channel.send(Embed);
});
};
我的代码根本不工作
当我运行它时 - 什么都没有发生,没有错误,没有消息,什么都没有。
尝试记录所有内容,但仍然没有任何结果。
我也尝试使用console.log() 记录所有内容,但没有任何效果
我提醒:我需要向我的机器人所在的所有服务器发送一条消息,但只有一个通道
【问题讨论】:
-
什么不起作用?什么都没有发生?有错误吗?有什么意外行为吗?
-
哦,是的,对不起,我会编辑我的错误帖子
-
你可以查看this的问题,可能对你有帮助
标签: node.js server discord discord.js bots