创建消息->机器人反应

时间:2020-06-09 14:40:39

标签: discord discord.js

Id类似于编写程序,它将每隔2分钟用我的User-ID将消息/机器人命令(“!work”)发送到不和谐的频道中。 它可以正常工作,但该漫游器不会对该消息做出响应/反应。

代码:

bot.on("message", msg => {

    function work() {
        let guild = bot.guilds.get('695350286516092968'), channel;
        channel = guild.channels.get('719889410149318696').send("!work");
        console.log(new Date() + " " + msg);

    }

    if (msg.content.startsWith(prefix + "_money")) {
        console.log(new Date() + " " + msg);
        setInterval(work, 120000);
    };
}
);

const prefix = "$Bot";

2 个答案:

答案 0 :(得分:0)

function work() {
    let guild = bot.guilds.get('695350286516092968'), channel;
    channel = guild.channels.get('719889410149318696').send("!work");
    message.react("?")
    console.log(new Date() + " " + msg);
}

答案 1 :(得分:0)

好吧,您需要通过添加if语句来处理该消息

if(msg.content === "!work") {
  //logic
  msg.channel.send("Hey");
}

尽管您当前使用的代码将来会出现一些错误,其中之一是:您可以设置多个时间间隔,一种解决方法是将其设置为一个时间间隔变量,这样您也可以清除如果需要的话,以后间隔

const prefix = "$Bot";
let interval;

function work() {
        const channel = bot.channels.get('719889410149318696');
        channel.send("!work");
        console.log(new Date() + " " + msg);
}

bot.on("message", msg => {
    if (msg.content.startsWith(prefix + "_money")) {
        if(interval) return;
        console.log(new Date() + " " + msg);
        interval = setInterval(work, 120000);
    };
});