LoginSignup
1
1

More than 3 years have passed since last update.

A3RTのTalk APIで返事をしてくれるDiscord Botを作ってみた

Posted at

簡単なDiscord Botの作り方(初心者向け)
自動応答のDiscord Botを完全無料で構築する[gas][glitch]

これらの記事を参考にしながら、A3RTのTalk APIを使ったDiscordのbotを作ってみました。
Botにリプライをすると、返事をしてくれます。

以下のコードはBotの返信部分の実装です。


const discord = require("discord.js");
const client = new discord.Client();

client.on("message", message => {
//メッセージが他のユーザーによるものだったら反応する
if (message.isMemberMentioned(client.user)) {

  //先頭のユーザーIDを削除する
  var talkMassage = message.content.slice(22);

  const fetch = require('node-fetch');

  const params = new URLSearchParams();
  params.append('apikey', "APIキー");
  params.append('query', talkMassage);

  fetch("https://api.a3rt.recruit-tech.co.jp/talk/v1/smalltalk", { method: 'POST', body: params } )
    .then(Response => {
    Response.json().then(Data => {
      message
      .reply(Data.results[0].reply);
    });
  });
  }
});

何かありましたら気軽にコメントをください。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1