[英]Discord.js bot help needed - how can I make my bot auto do a task every 6 hours without sending it a command?
[英]discord.js question. how do i make the bot give a different response to one command?
所以我有命令-joke
我希望機器人對該命令給出隨機響應。 如何將其添加到此代碼中:
module.exports = {
name: 'joke',
description: "tells a joke",
execute(message, args) {
message.channel.send('Why do we tell actors to break a leg? Because every
play has a cast');
}
}
使用數組來存儲您的笑話。
假設你的數組被稱為笑話:
const getJoke = () => {
return jokes[Math.floor(Math.random() * jokes.length))];
}
然后,這應該會從您的陣列中隨機獲得一個。 只需將 function 的 output 發送給您的用戶
創建一個帶有笑話的數組:
const jokes = ["Joke1", "Joke2", "Joke3"];
並在隨機索引處從數組中獲取一個笑話:
const randJoke = jokes[Math.floor(Math.random() * jokes.length)];
然后在當前文本頻道中發送隨機笑話:
message.channel.send(randJoke);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.