2022年8月25日 星期四

[Discord]機器人的的login與接收訊息/反應(discord.js:14.3)

 最近又開始寫起Discord機器人, 用的discord.js是14.3的版本, 跟上次寫的時候用的12.3版有一些差異, 於此記錄一下


Login

12.3的login:
const { Client } = require('discord.js'); const client = new Client({ partials: [/*需要的partial字串, ex:'CHANNEL'*/] }); client.login(/*機器人的token*/);

14.3的login:
const { Client, GatewayIntentBits, Partials } = require('discord.js'); const client = new Client({ intents: [/*需要的GatewayIntentBits列舉, ex:GatewayIntentBits.Guilds*/], partials: [/*需要的Partials列舉, ex: Partials.Channel*/] }); client.login(/*機器人的token*/);