LoginSignup
1
1

More than 3 years have passed since last update.

#twitch の配信中のチャットログを #discord でロギングするBOT

Last updated at Posted at 2020-02-07

githubと改行ルールが違って二重管理になるため、ここにはgithubのREADME.mdのコピペを載せます。
(githubにあっても検索で探せないため。)
https://github.com/github895439/twitch_chat_logging_bot

README.md
本内容を利用した場合の一切の責任を私は負いません。

環境
OS
OS 名: Microsoft Windows 10 Home
OS バージョン: 10.0.18362 N/A ビルド 18362
システムの種類: x64-based PC

node.js
node-v10.16.0-win-x64
discord.js@11.5.1
tmi.js@1.5.0

概要
以前に使用していた配信サイトは掲示板の機能を使っていたためなのか、配信中にチャットのログを視聴者が遡ることができた。
これができると、配信を途中から見た人も話の流れがわかる。
twitchとyoutubeはこれができないのが不便。
てことで、discordでロギングすればいいのではと思った。
(もちろん、遡るためには視聴者がdiscordに参加する必要がある。)
実現方法は、twitch BOTとdiscord BOTを組み合わせる。
twitch BOTがtwitchチャットのメッセージを検出したら、そのメッセージをdiscordチャネルに送信する。

手順
BOT用twitchアカウント作成

BOTのOAuthトークン作成
BOT用twitchアカウントでログインして下記で作成する。
(tmi.jsを使わない場合はこの限りではないかも。)
https://twitchapps.com/tmi/

discord bot設定
公式でわかりやすいものが見つからなかったので、参考のWebページで設定する。
BOT PERMISSIONSはチャネルの作成・削除もするため、下記をONにする。

Send Messages
Manage Channels
Manage Roles
node.jsにtmi.jsモジュールをインストール(※markdownのせいで番号がおかしく、手順の続き)
npm install tmi.js

node.jsにdiscord.jsモジュールをインストール
npm install discord.js

本ツールをダウンロード
https://github.com/github895439/twitch_chat_logging_bot

ダウンロードしたものを展開

ツールの設定
twitch_chat_logging_bot.js内の下記を設定する。

const config =
    {
        twitch:
            {
                botUsername: "<BOT用twitchアカウント名>",
                botPassword: "<twitch BOTのOAuthトークン(Webページにある先頭の「oauth:」も含めて)>",
                channel: "<配信者のアカウント名>"
            },
        discord:
            {
                guild: "<ロギングするdiscordサーバ名>",
                token: "<discord BOTのOAuthトークン>"
            }
    };
ツールを実行(※markdownのせいで番号がおかしく、手順の続き)
>node twitch_chat_logging_bot.js
INPUT 'E' TO STOP
Connected Discord.
[21:30] info: Connecting to irc-ws.chat.twitch.tv on port 80..
[21:30] info: Sending authentication to server..
[21:30] info: Connected to server.
[21:30] info: Executing command: JOIN #cyacya_1451
Connected Twitch.
[21:30] info: [#cyacya_1451] <twitch_chat_logging_bot>: I am ready for Twitch!
Ready Twitch.
Ready Discord.
[21:31] error: No response from Twitch.
BOTの終了(※markdownのせいで番号がおかしく、手順の続き)
「e」キーを押し、Enterキーを押すと停止する。
(discordチャネルを削除するため。
Ctrl+cで強制終了した場合はロギングしているdiscordの#twitch_chat_logチャネルが増殖していくと思う。)
備考
配信中を目的としているが、アーカイブ内のシーク的な使い方もできるため、discordチャネルの削除はツールの開始時に行う。
(次回の配信まで直近の配信のコメントが残る。)
ログなので、discordチャネルはサーバオーナとBOT以外はpostさせない。
参考に書かれているが、discordの開発サイドではサーバのことをギルドというらしい。

参考
twitch API
https://dev.twitch.tv/docs/api/reference

twitch Chatbots & IRC
https://dev.twitch.tv/docs/irc

tmi.js
https://gist.github.com/twitchdevelopers/afda75fe0a43453e97e97b25232778de https://github.com/tmijs/docs https://github.com/tmijs/docs/tree/gh-pages/_posts

discord developer portal
https://discordapp.com/developers/applications/

discord bot設定
https://note.com/bami55/n/ncc3a68652697 https://qiita.com/PinappleHunter/items/af4ccdbb04727437477f https://liginc.co.jp/370260

discord.js
https://discord.js.org/#/ https://github.com/discordjs/discord.js

主な履歴
2020/02/25
 discordチャネルの削除をツール終了時ではなく開始時に変更
  最新アーカイブのコメントをdiscordに残し、アーカイブ内のシーク的な使い方をできるようにするため。
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