简体   繁体   English

为什么我的频道消息发送代码不起作用?

[英]Why my channel message send code isn't working?

I am trying to send a message at a specific hour on my discord bot but my code isn't working.我正在尝试在特定时间在我的 discord 机器人上发送消息,但我的代码无法正常工作。 I get a "Cannot read property 'send' of undefined" error.我收到“无法读取未定义的属性‘发送’”错误。 Send part isn't working, i don't know why.发送部分不起作用,我不知道为什么。 I used the same send code elsewhere but it works there.我在其他地方使用了相同的发送代码,但它在那里工作。 The code i am using is like this.我正在使用的代码是这样的。 It was saying message is unidentified before i wrote 'message' in function so i solved it like that.在我在 function 中写“消息”之前,它说消息身份不明,所以我就这样解决了。 I am a beginner so take it easy on me, Please help, thanks!我是初学者,请放心,请帮助,谢谢!

    var schedule = require('node-schedule');

var scheduleFunction = schedule.scheduleJob('00 19 * * *', function(message) {
    message.channel.send('test!');
});

It seems message doesn't refer to a specific message and is thus coming back undefined.似乎message没有引用特定消息,因此返回未定义。 Instead, use相反,使用

var channel = <ID of channel you want the message to be sent to>
client.channels.cache.get(channel).send('test!'):

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM