对消息discord.js的随机响应 [英] Random response to message discord.js

查看:35
本文介绍了对消息discord.js的随机响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个基本的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’

推荐答案

此代码应为您工作,它从其中包含您的消息的数组中选择一个随机值.

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)

这篇关于对消息discord.js的随机响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆