Random response to message discord.js

筅森魡賤 提交于 2021-01-07 02:45:12

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!