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

Discord.js 在嵌入鏈接中將 api 連接到不和諧機器人

Discord.js connecting api to discord bot in an embed link(Discord.js 在嵌入鏈接中將 api 連接到不和諧機器人)
本文介紹了Discord.js 在嵌入鏈接中將 api 連接到不和諧機器人的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我一直在嘗試編寫一個機器人來發(fā)布和嵌入鏈接,以根據(jù)用戶輸入的數(shù)字顯示漫畫的標(biāo)題、標(biāo)簽等.我正在查看的 api 是

I've been trying to code a bot that will post and embed link to show the title of manga, tags, etc. based on what digits user input. The api that I'm looking at is This and I want to know what's the best way of connecting it to my discord bot?

client.on("message", (message) => {
    if (!message.content.startsWith(prefix)) return;
    if (message.content.startsWith(prefix)) {
        let chosenNum = message.content.match(/d+/)?.[0].slice(0);
        if (chosenNum.length > 6) {
          message.channel.send("**1-6 digits only**")
        } else{
        message.channel.send(`${chosenNum}`)
      }
    }
});

解決方案

The package you chose has a really simple API. All you need is the nhentai.exists() and nhentai.getDoujin() methods. With the first one you can check if the user submitted ID exists, and with the second one you can fetch a JSON object that you can use to populate your embed.

Check out the example below:

const { Client, MessageEmbed } = require('discord.js');
const nhentai = require('nhentai-js');

const client = new Client();
const prefix = '!';

client.on('message', async (message) => {
  if (!message.content.startsWith(prefix)) return;
  // create an args variable that slices off the prefix and splits it into an array
  const args = message.content.slice(prefix.length).split(/ +/);
  // create a command variable by taking the first element in the array
  // and removing it from args
  const command = args.shift().toLowerCase();

  if (command === 'hen') {
    const chosenNum = args[0]?.match(/d+/)?.[0];

    if (!chosenNum)
      return message.channel.send('You need to provide a number');

    if (chosenNum.length > 6)
      return message.channel.send('**1-6 digits only**');

    try {
      if (!(await nhentai.exists(chosenNum)))
        return message.channel.send(`No results found for "${chosenNum}".`);

      // res is your JSON object, feel free to console.log its content
      const res = await nhentai.getDoujin(chosenNum);
      const embed = new MessageEmbed()
        .setColor('#ed2553')
        .setTitle(res.title)
        .setImage(res.pages[0])
        .setURL(res.link)
        .addField('Pages', res.details.pages[0], true)
        .addField('Uploaded', res.details.uploaded[0], true);

      if (res.details.languages)
        embed.addField('Languages', res.details.languages.join(', '), true);
      if (res.details.characters)
        embed.addField('Top characters', res.details.characters.slice(0, 3).join(', '), true);
      if (res.details.tags)
        embed.addField('Top tags', res.details.tags.slice(0, 3).join(', '), true);

      return message.channel.send(embed);
    } catch (err) {
      console.log(err);
      return message.channel.send('Oops, there was an error. Maybe try again?!');
    }
  }
});

這篇關(guān)于Discord.js 在嵌入鏈接中將 api 連接到不和諧機器人的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(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(如何讓我的機器人提及發(fā)出該機器人命令的人)
How to fix Must use import to load ES Module discord.js(如何修復(fù)必須使用導(dǎo)入來加載 ES 模塊 discord.js)
How to list all members from a specific server?(如何列出來自特定服務(wù)器的所有成員?)
Discord bot: Fix ‘FFMPEG not found’(Discord bot:修復(fù)“找不到 FFMPEG)
Welcome message when joining discord Server using discord.js(使用 discord.js 加入 discord 服務(wù)器時的歡迎消息)
主站蜘蛛池模板: 欧美一区二区三区小说 | 国产专区免费 | 精品视频在线观看 | 欧美专区日韩专区 | 放个毛片看看 | 亚洲欧美日本在线 | 国产免费av在线 | 99re国产 | www.日本国产 | 亚洲一区播放 | 久久久国产一区二区三区 | 日本午夜网 | 欧美一区二区三区高清视频 | 日韩精品色网 | 久久国产一区二区三区 | 一区中文字幕 | 天天操天天干天天爽 | 国产精品爱久久久久久久 | 精品自拍视频在线观看 | www.久久久.com| 欧美成人a∨高清免费观看 91伊人 | 亚洲成人三级 | 一级片免费视频 | 国产中文字幕在线观看 | 久久精品无码一区二区三区 | 成人av免费在线观看 | 国产精品色 | 亚洲二区在线 | 91国内视频在线 | 欧美日产国产成人免费图片 | 天天夜夜人人 | 久久久女女女女999久久 | 毛片免费看| 一区二区在线免费观看 | 久久91精品国产 | 国产美女高潮 | 在线视频91 | 天天躁日日躁狠狠躁2018小说 | 欧美 日韩 在线播放 | 精品国产一区二区三区日日嗨 | 亚洲伊人久久综合 |