Home > Back-end >  TypeError: targetchannel.send is not a function
TypeError: targetchannel.send is not a function

Time:12-13

Node version : v16.13.1

Discord.js version : 13.3.1

TypeError: targetchannel.send is not a function

How to fix this Error?

Code:

fs.readdir('channels', function (err, files) {
if (err) {
    return console.log('Unable to scan directory: '   err);
}
files.forEach(function (file) {
    targetchannel = client.channels.fetch(fs.readFileSync('channels/'   file,{encoding:'utf8'}))
    console.log(targetchannel)
    targetchannel.then((value) => {
            targetchannel.send("asdra")
});

});
});

log of targetchannel = Promise { < pending > }

image of errors https://i.stack.imgur.com/ixfK5.png

CodePudding user response:

targetChannel is still the pending promise. Use value.send() instead since value is the resolved promise

targetchannel.then((value) => {
    value.send("asdra")
})

CodePudding user response:

You need to await since <Channel>.fetch is an async method.

targetchannel = await client.channels.fetch()
  • Related