[英]discord.js bot for replacing “,”
我正在創建一個帶有節點的 discord 機器人。 我希望當用戶發送帶有前綴“doc”的消息時,它將所有“,”替換為“word1”“word2”“word3”等之間的隨機詞......我不太了解這個領域. 我到了這一點,我不知道該怎么做:
bot.on("message", async message => {
if(message.author.bot) return;
if(message.channel.type === "dm") return;
let prefix = botconfig.prefix;
let messageArray = message.content.split(" ");
let cmd = messageArray[0];
let args = messageArray.slice(1);
//replace ","
});
我到了這一點:
var words = [" word1 "," word2 "," word3 "," word4 "," word5 "," word6 "];
bot.on("message", async message => {
if (message.content.includes("doc ")) {
if(message.content.includes(",")){
var txt = message.content.replace(/doc /gi, "");
var rando = Math.floor((Math.random() * 6) + 1);
var txt = txt.replace(/,/gi, words[rando]);
message.channel.send(txt);
}else{
message.channel.send("the text doesn't contain any comma");
}
}
輸入:doc 我遇到了哈利,我們一起去游泳,然后哈利回家了。
output:我遇到了哈利 word5 我們一起去游泳 word5 然后哈利回家了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.