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

如何在 Discord.js 中添加錯(cuò)誤消息?

How can i add Error Message in Discord.js?(如何在 Discord.js 中添加錯(cuò)誤消息?)
本文介紹了如何在 Discord.js 中添加錯(cuò)誤消息?的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

我創(chuàng)造了一個(gè)真心話大冒險(xiǎn)的機(jī)器人.我的前綴是 + 現(xiàn)在我想向它添加一條錯(cuò)誤消息.我有兩個(gè)變量t".d"如果有人鍵入 +something which does not match my variable to send a Message that Invalid Command +help for Help"你們能幫幫我嗎?

I Create a Truth and dare Bot. My Prefix is + Now I want to add an error message to it. I have two variables "t" "d" If anyone types +something which does not match my variable to send a Message that "Invalid Command +help for Help" Can you guys help me?

const Discord = require('discord.js');
const client = new Discord.Client();
const keepAlive = require("./server")
const prefix = "+";

// ======== Ready Log ========
client.on ("ready", () => {
    
    console.log('The Bot Is Ready!');
    client.user.setPresence({
      status: 'ONLINE', // Can Be ONLINE, DND, IDLE, INVISBLE
      activity: {
          name: 'Truth Or Dare | +help',
          type: 'PLAYING', // Can Be WHATCHING, LISTENING
      }
  })
  }); 
// ======== Code ========

client.on('message', message => {
const help = new Discord.MessageEmbed()
    .setColor('#72dfa3')
    .setTitle(`Truth Or Dare`)
    .addFields(
        { name: '``+help``', value: 'For help'},
    { name: '``+t``', value: 'For Truth'},
    { name: '``+d``', value: 'For Your Dare'},
    { name: '``Created By``', value: 'AlpHa Coder [Labib Khan]'},
    )
    .setTimestamp()
  .setFooter(`${message.author.username}`, message.author.displayAvatarURL());
  if (message.content === `${prefix}help`) {
    message.channel.send(help);
  }
});

// ========= Truth =========
client.on('message', message => {
const t = [
"If you could be invisible, what is the first thing you would do?", 
"What's the strangest dream you've ever had?",
"What are the top three things you look for in a boyfriend/girlfriend?",
"What is your worst habit?",
"How many stuffed animals do you own?",
"What is your biggest insecurity?"
]
const truth = t[Math.floor(Math.random() * t.length)];
if (message.content === `${prefix}t`) {
  message.channel.send(truth);
}
});

// ========= Dare =========
client.on('message', message => {
  const d = [
"Do a free-style rap for the next minute.",
"Let another person post a status on your behalf.",
"Hand over your phone to another player who can send a single text saying anything they want to anyone they want.",
"Let the other players go through your phone for one minute.",
"Smell another player's armpit",
"Smell another player's barefoot.",
"Tell everyone your honest opinion of the person who sent this command."
  ]
  const dare = d[Math.floor(Math.random() * d.length)];
  if (message.content === `${prefix}d`) {
    message.channel.send(dare);
  }
});


const token = process.env.TOKEN;
keepAlive()
client.login(token);

請(qǐng)解釋清楚,以便我理解.提前謝謝

Please explain clearly so that I can understand. Advance Thank you

推薦答案

不要使用單獨(dú)的 message 事件處理程序,使用一個(gè).您可以通過(guò)使用 來(lái)利用它if else 鏈.您正在嘗試通過(guò)鏈匹配命令,如果未找到匹配項(xiàng),則在 else 中(意味著鏈中的每個(gè)先前檢查都失敗)您回復(fù)用戶說(shuō):

Don't use separate message event handlers, use one. You can take advantage of that by using if else chain. You are trying to match the command through the chain, if no match was found, in else (meaning every previous check in the chain failed) you reply to the user by saying:

命令無(wú)效,請(qǐng)鍵入 +help 尋求幫助.".

"Invalid command, type +help for help.".

還要檢查開(kāi)頭的前綴.如果沒(méi)有前綴,則從函數(shù)返回.這樣你就不必在匹配消息內(nèi)容時(shí)將其寫(xiě)入 if 語(yǔ)句.

Also check for the prefix at the beginning. If there is no prefix, return from the function. That way you don't have to write it to the if statements when matching the message content.

// Array of possible truth replies
const t = [
    "If you could be invisible, what is the first thing you would do?", 
    "What's the strangest dream you've ever had?",
    "What are the top three things you look for in a boyfriend/girlfriend?",
    "What is your worst habit?",
    "How many stuffed animals do you own?",
    "What is your biggest insecurity?"
];

// Array of possible dare replies
const d = [
    "Do a free-style rap for the next minute.",
    "Let another person post a status on your behalf.",
    "Hand over your phone to another player who can send a single text saying anything they want to anyone they want.",
    "Let the other players go through your phone for one minute.",
    "Smell another player's armpit",
    "Smell another player's barefoot.",
    "Tell everyone your honest opinion of the person who sent this command."
];

// Handle all commands here
client.on('message', message => {

    // Don't reply to itself
    if (message.author.id === client.user.id) return;

    // If there is no + (prefix) at the beginning of the message, exit function
    if (!message.content.startsWith(prefix)) return;

    // Remove the prefix from the message -> our command
    const command = message.content.substring(prefix.length);

    // Match the command
    if (command === "t") { // Truth
        const truth = t[Math.floor(Math.random() * t.length)];
        message.channel.send(truth);
    } else if (command === "d") { // Dare
        const dare = d[Math.floor(Math.random() * d.length)];
        message.channel.send(dare);
    } else if (command === "help") { // Help

        const help = new Discord.MessageEmbed()
            .setColor('#72dfa3')
            .setTitle(`Truth Or Dare`)
            .addFields(
                { name: '``+help``', value: 'For help' },
                { name: '``+t``', value: 'For Truth' },
                { name: '``+d``', value: 'For Your Dare' },
                { name: '``Created By``', value: 'AlpHa Coder [Labib Khan]' },
            )
            .setTimestamp()
            .setFooter(`${message.author.username}`, message.author.displayAvatarURL());

        message.channel.send(help);

    } else { // No match found, invalid command
        message.channel.send("Invalid command, type `+help` for help.");
    }

});

這篇關(guān)于如何在 Discord.js 中添加錯(cuò)誤消息?的文章就介紹到這了,希望我們推薦的答案對(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í)的歡迎消息)
主站蜘蛛池模板: 国产欧美精品一区二区三区 | 久久99精品久久久久久青青日本 | 欧美在线视频观看 | 日韩aⅴ在线观看 | 免费成人国产 | 欧美激情在线一区二区三区 | 国产激情精品视频 | 欧美日日 | 精品日韩一区 | 亚洲综合区 | 久久99视频 | 亚洲 中文 欧美 日韩 在线观看 | 成人免费一区二区三区视频网站 | 91观看| 精品国产91| 日本亚洲欧美 | 超碰人人爱 | 亚洲精品久久久一区二区三区 | 国产精品久久久久久久久久久久久 | 国产区在线观看 | 亚洲精品第一 | 久久久久久www | 午夜视频免费在线观看 | 国产乱码精品一区二区三区五月婷 | 一级毛片观看 | 日本三级线观看 视频 | 国产一极毛片 | 午夜av一区二区 | 亚洲欧美日韩在线不卡 | h视频在线观看免费 | 亚洲国产高清高潮精品美女 | 日韩av成人| 福利视频一区二区 | 免费在线观看一区二区三区 | 伊人色综合久久久天天蜜桃 | 青青草一区 | 欧美日韩国产传媒 | 国产一区二区三区视频在线观看 | 久久99精品国产 | 亚洲国产一区二区三区, | 久久99蜜桃综合影院免费观看 |