久久久久久久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í)的歡迎消息)
主站蜘蛛池模板: 久久一二区 | 午夜欧美a级理论片915影院 | 午夜一区| 免费黄色录像片 | 偷牌自拍 | 国产精品中文字幕在线播放 | 精品乱子伦一区二区三区 | 五月综合激情婷婷 | 国产高清免费视频 | 亚洲成人精品一区 | a级片在线| 少妇特黄a一区二区三区88av | 91在线观看免费视频 | 成人网视频 | 亚洲精品久久久一区二区三区 | 91精品国产乱码麻豆白嫩 | 深夜福利影院 | av成人在线观看 | 日韩一区二区三区在线观看 | 黑人巨大精品欧美一区二区免费 | 亚洲欧美日韩一区 | 国产日韩在线观看一区 | 香蕉久久久| 亚洲精品99| 欧美不卡一区二区 | 欧美一级毛片在线播放 | 99爱在线 | 日本黄色短片 | 国产激情视频在线免费观看 | 高清人人天天夜夜曰狠狠狠狠 | 在线观看国产91 | 婷婷五月色综合 | 一区二区不卡视频 | 超黄视频网站 | 99热精品久久 | 三级av在线 | 亚洲成人国产精品 | 午夜激情在线 | 综合国产 | 狠狠狠干 | 亚洲天堂一区 |