Disord Bot自动发送消息

时间:2020-08-11 16:41:21

标签: javascript node.js discord discord.js

所以这是我第一次使用DiscordJS(或一般编码)进行编码,我需要一些帮助以使bot自动在特定频道中发送消息。请给我一些帮助吗?谢谢!

这是我的代码:

const Discord = require("discord.js");
const client = new Discord.Client();

client.once("ready", () => {
    console.log("LemonBot is online!");
});

const express = require("express");
const app = express();
const guildId = "739855462274695188";
const channelId = "739875350594584707";
const message = "!d bump"

client.login(my discord bot token)

1 个答案:

答案 0 :(得分:0)

const Discord = require("discord.js");
const client = new Discord.Client();

client.on("ready", () => {
    console.log(`${client.user.tag} is online!`);

    // Getting the channel from client.channels Collection.
    const Channel = client.channels.cache.get("739875350594584707");
    // Checking if the channel exists.
    if (!Channel) return console.error("Couldn't find the channel.");
    // Sending "!d bump" to the channel.
    Channel.send("!d bump").catch(e => console.log(e));
});

client.login(process.env.DISORD_AUTH_TOKEN)