Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用discord.js发送定期消息时出现问题_Discord.js - Fatal编程技术网

使用discord.js发送定期消息时出现问题

使用discord.js发送定期消息时出现问题,discord.js,Discord.js,我明白这个问题 setInterval(function(){ var randommessage = Math.floor(Math.random() * 5) + 1; var randomsentence = Math.floor(Math.random() * 10) + 1; if(randommessage === 1){ console.log("Silence...") } else { if(randoms

我明白这个问题

    setInterval(function(){
    var randommessage = Math.floor(Math.random() * 5) + 1;
    var randomsentence = Math.floor(Math.random() * 10) + 1;
    if(randommessage === 1){
        console.log("Silence...")
    } else {
        if(randomsentence === 1){
            client.channels.get('532065669718736906').send("Do you ever wonder why we were born... whats our purpose?")
        } else if(randomsentence === 2){
            client.channels.get('532065669718736906').send("So... you come here often?")
        } else if(randomsentence === 3){
            client.channels.get('532065669718736906').send("What is the point of this server?")
        } else if(randomsentence === 4){
            client.channels.get('532065669718736906').send("Why do i exist?")
        } else if(randomsentence === 5){
            client.channels.get('532065669718736906').send("Why are we still here... just to suffer..")
        } else if(randomsentence === 6){
            client.channels.get('532065669718736906').send("Begels are life!")
        } else if(randomsentence === 7){
            client.channels.get('532065669718736906').send("Banana Bros!!")
        } else if(randomsentence === 8){
            client.channels.get('532065669718736906').send("Is the number 3 a myth?")
        } else if(randomsentence === 9){
            client.channels.get('532065669718736906').send("*Shuffles through papers*")
        } else if(randomsentence === 10){
            client.channels.get('532065669718736906').send("In the end.. it doesnt even matter!")
        } else {
            client.channels.get('532065669718736906').send("randomness is gud")
        }
    }
}, 3000);
这是假设发送定期消息,除非我得到错误

TypeError: Cannot read property 'send' of undefined
    at Timeout._onTimeout (C:\Users\User\Documents\Discord Intro Bot\index.js:52:46)
    at listOnTimeout (internal/timers.js:531:17)
    at processTimers (internal/timers.js:475:7)
我已经尝试了所有的方法来解决这个问题,甚至是事先找到频道然后发送给它,但是它仍然认为这个频道不存在


我不想使用on消息,因为我的服务器非常不活跃,我用它来给bot添加一些情绪

您使用的是什么版本的Discord.js?Client.Channel在v12中已从集合更改为。请在问题中使用适当的语言。现在,我删掉了不必要的坏话。你能不能更详细地解释一下(没有代码)你想实现什么?就像塔拉泽说的,如果你使用的是v12,你需要执行
client.channels.cache.get('532065669718736906')。send('…')