久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

隨機(jī)消息回復(fù) Discord.js 2020

Random Message Reply Discord.js 2020(隨機(jī)消息回復(fù) Discord.js 2020)
本文介紹了隨機(jī)消息回復(fù) Discord.js 2020的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

我一直在嘗試隨機(jī)回復(fù),但我發(fā)現(xiàn)的其他答案和教程并不完全有效.大多數(shù)教程都有

I've been trying to put a random reply but the other answers and tutorials I found didn't exactly work. Most of the tutorials have

const messages = [
    "seriously?! You thought I would reply", 
    "hm, yeh thats a pretty random question - Don't ya think?", 
    "Ok I'm actually running out of options now", 
    "Please stop asking me", 
    "Ok, im done!",
    "?"
];

const randomMessage = messages[Math.floor(Math.random() * messages.length)];

完成并發(fā)送消息

module.exports = {
    name: 'random',
    description: 'random?',

    execute(message, args){
        message.channel.send(randomMessage);
    }
}

但是,答案并不是真正隨機(jī)的.當(dāng)我從命令提示符/終端運(yùn)行機(jī)器人時(shí),機(jī)器人會(huì)得到一個(gè)隨機(jī)答案,但當(dāng)用戶實(shí)際運(yùn)行它時(shí),它只會(huì)給出一個(gè)答案.

However, the answer isn't really randomized. When I run the bot from the command prompt/terminal, the bot gets a random answer, but then when the user actually runs it, it only gives one answer.

例如,答案可以是 1、2 或 3.當(dāng)我運(yùn)行機(jī)器人時(shí),會(huì)隨機(jī)選擇一個(gè)答案;假設(shè)2.那么無(wú)論所有用戶說(shuō)什么,它都只會(huì)給出2的答案作為回復(fù).如果我再次運(yùn)行機(jī)器人并得到,比如說(shuō) 3,那么回復(fù)將只有 3.

For example, the answers can be 1, 2, or 3. When I run the bot one answer gets picked randomly; let's say 2. Then no matter what all users say, it will only give the answer of 2 as the reply. If I run the bot again and get, let's say 3, then the reply will only be 3.

推薦答案

正如 Gabriel Andrade 所說(shuō),您需要將 randomMessage 常量放在執(zhí)行函數(shù)中.如果你不這樣做,隨機(jī)消息只會(huì)在你啟動(dòng)機(jī)器人時(shí)被評(píng)估一次.

As Gabriel Andrade said, you need to put the randomMessage constant inside of the execute function. If you don't, the random message will only be evaluated once when you start the bot.

module.exports = {
    name: 'random',
    description: 'random?',
    execute(message, args){
        // Now the randomMessage will be recalculated every time the command is run
        const randomMessage = messages[Math.floor(Math.random() * messages.length)];
        message.channel.send(randomMessage);
    }
}

這篇關(guān)于隨機(jī)消息回復(fù) Discord.js 2020的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

discord.js v12: How do I await for messages in a DM channel?(discord.js v12:我如何等待 DM 頻道中的消息?)
how to make my bot mention the person who gave that bot command(如何讓我的機(jī)器人提及發(fā)出該機(jī)器人命令的人)
How to fix Must use import to load ES Module discord.js(如何修復(fù)必須使用導(dǎo)入來(lái)加載 ES 模塊 discord.js)
How to list all members from a specific server?(如何列出來(lái)自特定服務(wù)器的所有成員?)
Discord bot: Fix ‘FFMPEG not found’(Discord bot:修復(fù)“找不到 FFMPEG)
Welcome message when joining discord Server using discord.js(使用 discord.js 加入 discord 服務(wù)器時(shí)的歡迎消息)
主站蜘蛛池模板: 久久在线精品 | 久久国产精品偷 | 福利国产 | 国内自拍偷拍视频 | 精品久久久久久久 | 精品婷婷 | 日韩视频在线一区 | 狠狠干狠狠操 | 日韩久久在线 | 国产一区二区三区日韩 | 日本精品久久 | 久久久亚洲 | www.中文字幕.com| 亚洲一区二区三区在线免费观看 | 欧美久久久久久 | 国产综合av | 日本不卡一区 | 亚洲国产精品一区在线观看 | 国产精品人人做人人爽 | 男女羞羞视频网站 | 一区二区精品 | 国产亚洲www | 成人亚洲 | 国产精品a久久久久 | 日韩一区精品 | 欧洲视频一区二区 | 久久免费精品视频 | 亚洲精选一区二区 | 国产成人99久久亚洲综合精品 | 国产精品久久久久无码av | 99re视频在线免费观看 | 久久久久久国产精品免费免费 | 日韩美女在线看免费观看 | 91在线电影 | 国产精品久久 | 欧美精品一区二区三区在线四季 | 国内精品久久精品 | 亚洲人久久 | 青娱乐av | 久久久久久国产精品久久 | 欧美日韩亚洲一区 |