Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
529 views
in Technique[技术] by (71.8m points)

Discord.js can't read property send of undefined

so i've recently learned the basics of Discord.js and i tried to make my personal bot just for fun and one of the command in that bot is a !say command that lets me make the bot say whatever i want wherever i want but i'm always getting this error:Cannot read property 'send' of undefined

client.on('message', message =>{
    if(message.content === `${prefix}say`) {
        const arguements = message.content.slice(prefix.length).split(/ +/);
        const location = client.channels.chache.find(channel=>channel.id === arguements.shift());
        const whatToSay = arguements.slice(1);
        location.send(whatToSay);
        // !say (channel Id) blah blah blah
    }
});

I tried converting the arrow function into a normal function but it didn't work. I tried replacing the arguements.shift() in the 4th line and it still didn't work. I don't know where the mistake is

question from:https://stackoverflow.com/questions/65833208/discord-js-cant-read-property-send-of-undefined

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Check the spelling of the properties in your code.

client.channels.cache and arguments.shift


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...