Ive been trying to make my bot send random messages after some time. Here is the code that i tryed
randommessage = bot.SendMessage
randommessage({
to: channelID,
message: "I like turtles!"
wait (10)});
randommessage({
to: channelID,
message: "I like ponies!"
});
but to no avail it didnt work. I tried asking in a discord server but no one knew how to do it. Could somebody help me?
This doesn't look like a DiscordJS error, but instead a syntax error. The variable randommessage contains the function from bot.SendMessage without the value of bot. This is just how JavaScript works. This means that when you call randommessage, the function within it will have no instance of bot bound to it. In your error messages, you might see something regarding a value being undefined.
It is a simple fix for this error:
randommessage = bot.SendMessage.bind(bot)
When written this way, now the randommessage function has an instance of bot bound to it and can be executed successfully