如何让机器人在不使用命令的情况下向特定频道中的特定公会发送消息
How do you make a bot send a message to an specific guild in a specific channel without using commands
有人能帮帮我吗?我只是想让机器人在不请求的情况下向指定频道发送消息,消息应该每 x 分钟发送一次,但我只想知道如何发送。
您可以使用Client.guilds
(the list of all the guilds the client is a member of) and Guild.channels(公会拥有的所有频道的列表)。
要指定公会和频道,您可以使用他们的 ID:如果您在 Discord 中启用开发者模式(在用户设置 > 外观 > 高级下),您可以右键单击以复制公会、频道、用户等的 ID。
获得 ID 后,您可以使用 Collection.get()
获取它们。或者,您可以 .find()
按名称命名它们,但这并不理想,因为名称可以更改。
这是一个例子:
let guild = client.guilds.get('your guild ID as a string here'), // returns a Guild or undefined
channel;
if (guild) {
channel = guild.channels.get('your channel ID as a string here');
if (channel) setInterval(() => {channel.send("Here you can put the message and stuffs.");}, 10 * 60 * 1000);
else console.log("There's no channel with that ID."),
} else console.log("There's no guild with that ID.");
这只是核心概念,您显然可以修改它。
let guild = client.guilds.cache.get('your guild ID as a string here'), // returns 公会或未定义
频道;
如果(公会){
通道 = guild.channels.cache.get('your channel ID as a string here');
if (channel) setInterval(() => {channel.send("这里你可以放消息和东西。");}, 10 * 60 * 1000);
else console.log("没有该 ID 的频道。"),
} else console.log("没有该 ID 的公会。");
有人能帮帮我吗?我只是想让机器人在不请求的情况下向指定频道发送消息,消息应该每 x 分钟发送一次,但我只想知道如何发送。
您可以使用Client.guilds
(the list of all the guilds the client is a member of) and Guild.channels(公会拥有的所有频道的列表)。
要指定公会和频道,您可以使用他们的 ID:如果您在 Discord 中启用开发者模式(在用户设置 > 外观 > 高级下),您可以右键单击以复制公会、频道、用户等的 ID。
获得 ID 后,您可以使用 Collection.get()
获取它们。或者,您可以 .find()
按名称命名它们,但这并不理想,因为名称可以更改。
这是一个例子:
let guild = client.guilds.get('your guild ID as a string here'), // returns a Guild or undefined
channel;
if (guild) {
channel = guild.channels.get('your channel ID as a string here');
if (channel) setInterval(() => {channel.send("Here you can put the message and stuffs.");}, 10 * 60 * 1000);
else console.log("There's no channel with that ID."),
} else console.log("There's no guild with that ID.");
这只是核心概念,您显然可以修改它。
let guild = client.guilds.cache.get('your guild ID as a string here'), // returns 公会或未定义 频道;
如果(公会){ 通道 = guild.channels.cache.get('your channel ID as a string here'); if (channel) setInterval(() => {channel.send("这里你可以放消息和东西。");}, 10 * 60 * 1000); else console.log("没有该 ID 的频道。"), } else console.log("没有该 ID 的公会。");