LoginSignup
13
7

More than 5 years have passed since last update.

Discordの絵文字IDを確認する方法

Posted at

Discordの絵文字IDを確認する方法

Discordのbotで絵文字を利用したくて、色々調べた結果あんまり日本語の記事がなかったので備忘録代わりに。

結論

絵文字IDを調べたいサーバー(開発側だとGuild(ギルド)って言うらしいですね!)で、
\:emojiname:
バックスラッシュを付けて絵文字表示しようとすると
<:emojiname:275938272957>
と言うような表示になりIDを取得できます。

余談(discordgoでの絵文字の使い方)

discordgoを使ってDiscordのbotを作ろうかなって思っていて、botで絵文字表示をしようとしたところ絵文字にならない!ということに気づき、godocを読んでいたところ、Emojiという構造体があることを発見。
Emojiを取得できそうな関数がないかなと思って見てみると

func (*State) Emoji
func (s *State) Emoji(guildID, emojiID string) (*Emoji, error)
Emoji returns an emoji for a guild and emoji id.

説明文を見る限りこれっぽい!で、GuildIDとEmojiIDってなんだろ?となり、調べてみるとguildIDはサーバーのIDのこと、emojiIDは上で書いた方法で調べられるみたい。
最後にEmojiのままでは出力できないのでフォーマットをStringに変換する関数

func (*Emoji) MessageFormat
func (e *Emoji) MessageFormat() string
MessageFormat returns a correctly formatted Emoji for use in Message content and embeds

を利用して、絵文字の表示に成功しました。

ソースコード

discord_emoji.go
emoji,err := s.State.Emoji(GuildID,"123456748392")
if err != nil{
   panic(err)
}
sendMessage(s,c,emoji.MessageFormat())

参考文献

Can bots display custom emojis
ユーザー/サーバー/メッセージIDはどこで見つけられる?

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