こちらにアクセスして「New Application」を押します

BOTの名前を入力して「Create」

作成されました。

クリックして「Bot」タブから「Add Bot」

「Yes, do it!」

Botができました

画面下にスクロールして
PermissionsmをAdministratorに設定しておきます

サーバーに追加するには以下のURL
https://discord.com/oauth2/authorize?client_id=<client_id>&scope=bot
にアクセスします。
<client_id>には
「General Infomation」タブの「APPLICATION ID」の値を使用します

こんな画面が出てくるのでサーバーを選択して「認証」

該当サーバーに追加されました。

アプリのほうを開発していきます。
適当なディレクトリを作って
npm init -y

package.jsonを書き換えて
{
"name": "nurupo",
"version": "1.0.0",
"description": "Disord Bot",
{
"name": "Nurupo",
"version": "1.0.0",
"description": "Disord Bot",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"keywords": [],
"author": "Reiji",
"license": "MIT"
}
discord.jsをインストールします。
npm install discord.js

package.jsonにdependenciesが追加されています

index.jsファイルを作成します
const Discord = require('discord.js')
const client = new Discord.Client()
client.on('ready', () => {
console.log(`${client.user.tag}でログインしています。`)
})
client.on(`message`, async msg => {
if (msg.content === 'ぬるぽ') {
msg.channel.send('ガッ')
}
})
client.login('-----token-----')
—–token—– には

https://discord.com/developers/applications/ <client_id> /bot
TOKEN 「Copy」ボタンからコピーしたTokenを使用します
では動かしてみましょう
node index.js

Botがオンラインになりました

チャットに「ぬるぽ」と打つと


「ガッ」と返してくれます
コメント