问题
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’
回答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)
来源:https://stackoverflow.com/questions/61572364/random-response-to-message-discord-js