I am currently using discord.js to develop a discord bot. I wanted to create a function to send a message based on user input.
The code I have is as follows:
function myFunction(keyWord) {
client.on("messageCreate", myMessage => {
if (myMessage.content.bot) {
return
}
myMessage.channel.send(keyWord)
})
}
When I run this function in my code, the code seems to stop at the client.on section. It does not throw an error, it simply does not send the message or run any code beyond the client.on.
I appreciate any help!
myMessage.content returns a string; you are reading it as an object.
If you want to check if the author is a bot, you would read message.author.bot.
Try the following:
function myFunction(keyWord) {
client.on('messageCreate', (myMessage) => {
if (myMessage.author.bot)
return;
myMessage.channel.send(keyWord);
});
}