Cannot read property 'send' of underfined

前端 未结 2 1415
夕颜
夕颜 2021-01-28 01:19
const mudaeon = require(\'./mudaetime.json\');
const cron = require(\'cron\');
const Discord = require(\'discord.js\');
const clie         


        
2条回答
  •  北荒
    北荒 (楼主)
    2021-01-28 01:45

    You should not use the cache to access the channels but the (async) .fetch method:

    
    module.exports = {
        name: 'mudaetime',
        description: '...',
        async execute(message, args){
            if(mudaeon){
                const channel = await client.channels.fetch('222109930545610754')
                let scheduledMessage = new cron.CronJob("* * * * *", () => {
                    scheduledMessage.start()},
                    message.react('✅'),
                    channel.send("check $tu ! <@&id"))
            } else(!mudaeon);{
                cancel();
            }
        }
    }; 
    

    This should work better, a lot of methods are async in discord.js so becareful to properly await the values when calling such methods :)

    https://discord.js.org/#/docs/main/stable/class/ChannelManager?scrollTo=fetch

提交回复
热议问题