0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Discord.js v14でのチャンネル指定

Posted at

こんちゃ、りょうです。
ちょっとわかりにくいことしてる人見かけたので忘れないように書いとこうかと思って。

discord.js v14のチャンネル指定

discord.js v13で使用されていたisText()isVoiceが削除されまして。
かわりにChannelTypeを使うようになった

   const { ChannelType } = require("discord.js")
   /**
   なんちゃらかんちゃら
   **/
      if (channel.type === ChannelType.GuildText){
      //...

こんな感じ。
一応整数値でも表せるけどこっちのほうがわかりやすいとおもう。

よく使われるやつの対応表

Left align Right align 整数値
テキストチャンネル GuildText 0
DM DM 1
ボイスチャンネル GuldVoice 2
グループDM GroupDM 3
カテゴリー GuildCategory 4
アナウンスチャンネル GuildAnnounce 5
公開スレッド PublicThread 11
非公開スレッド PrivateThread 12
ステージチャンネル GuildStageVoice 13
フォーラム GuildForum 15
画像専用チャンネル GuildMedia 16

一応整数値版

テキストチャンネルの場合↓

      if (channel.type === 0){
      //...

これで一応はできるけど読みにくいし普通にChannelType使おう()

まとめ

読みやすいのが一番。

Discord荒らしなどの情報や対策の共有する自鯖↓
https://discord.gg/ESRGwGQhxc

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?