allowedMentions
discord.jsではsendなどのallowedMentionsがundefiendである場合はClientオプションのallowedMentionsが参照されます。
次のサンプルではhereメンション、ユーザー123へのメンション、ロール124へのメンションのすべてが有効です。
example1.jschannel.send({ content: "@here Hi there from <@123>, cc <@&124>" });
次の例ではメンションは一切行われません。
example2.jschannel.send({
content: "@everyone hi there, <@&123>",
allowedMentions: {
parse: []
}
});
次の例ではユーザー123とロール124にのみメンションが行われます。(everyoneメンションは行われません)
usersならびにrolesは値が
Falsyな場合無視されます。
example3.jschannel.send({
content: "@everyone <@123> <@&124>",
allowedMentions: {
parse: ["users", "roles"],
users: []
}
});
次の例ではeveryone、ユーザー123、ユーザー124へメンションが行われます。
ユーザー125、役職200へはメンションしたことになりません。
everyoneとしての意味しか持たないという意味です(everyoneの通知を無効にしている場合通知が届きません)。
example4.jschannel.send({
content: "@everyone <@123> <@124> <@125> <@&200>",
allowedMentions: {
parse: ["everyone"],
users: ["123", "124"]
}
});
次の例はparseにusersが含まれていて、かつ
TruthyなusersフィールドをallowedMentionsオブジェクトが持っているので不正です。
example5.js channel.send({
content: "@everyone <@123> <@124> <@125> <@&200>",
allowedMentions: {
parse: ["users"],
users: ["123", "124"]
}
});
次の例ではユーザー123のみにメンションが行われます。
125はcontent内にメンションが存在しないのでメンションされません。
example6.js channel.send({
content: "<@123> Time for some memes.",
allowedMentions: {
parse: ["users"],
users: ["123", "125"]
}
});