'Random response to message discord.js
I’m developing a basic discord.js moderation bot. As one of the functions I need the bot to respond to a message with one of many pre programmed responses.
Eg. Message = ‘Hello’ Response = ‘Hey’ or ‘Hi’ or ‘Goodday’
Solution 1:[1]
This code should work for you, It selects a random value from an array with your messages in it.
// your messages should go into this array
const messages = ["message one", "message two", "message three", "message four"]
const randomMessage = messages[Math.floor(Math.random() * messages.length)];
console.log(randomMessage)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Supesu |
