LoginSignup
1
0

More than 3 years have passed since last update.

JavaScriptのfilterをdiscord.jsで使ってみたメモ

Last updated at Posted at 2019-05-29

こんにちは、ほぼ毎日discord.jsでbot作ってる人です。(?)

前置き

今回は、discord.jsでJavaScriptのfilterを使ってみたのを記事にしてます
(説明が下手なのは許してください)
(まだ無知なことがいっぱい)
discord.js: https://discord.js.org/
Collection: https://discord.js.org/#/docs/main/stable/class/Collection

使い方

テキストチャンネルだけの数

const textChannels = message.guild.channels.filter(t => t.type == "text").size
message.channel.send(textChannels);

これでテキストチャンネルのみの数が表示されます。
説明すると
message.guild.channels.filter
(メッセージが送信されたギルドのチャンネルをフィルターする)
[以下略].filter.(t => t.type == 'text')
(tmessage.guild.channelsの省略版です(多分))
(t.type == 'text'はチャンネルのタイプです。)
'text'に入るのは、https://discord.js.org/#/docs/main/stable/class/Channel?scrollTo=type をご覧下さい。

追記
.sizeは○○の数です。

説明はこれで終わりです

終わりに

他にもfindとかあるのでいつかだそうかなと思ってます。

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