MessageComponents
イメージ
https://gyazo.com/b44f4966a8e331f11e0cd648555b87e5
参照
code:image.js
const Discord = require("discord.js");
const client = new Discord.Client({
intents: 0
});
client.token = process.env.DISCORD_TOKEN;
const BUTTON_STYLES = [
"PRIMARY",
"SECONDARY",
"SUCCESS",
"DANGER",
];
const CHANNEL_ID = "494780225280802819";
async function main() {
/**@type {Discord.TextChannel} */
const ch = await client.channels.fetch(CHANNEL_ID, {
allowUnknownGuild: true,
});
const buttons = [...BUTTON_STYLES.map(e => new Discord.MessageButton().setStyle(e).setCustomId(e)), new Discord.MessageButton().setStyle("LINK").setURL("https://example.com")]; buttons.forEach((button,index)=>{
button.setLabel(button.style);
button.setEmoji(String.fromCodePoint(0x1F1E6 + index));
});
await ch.send({
content: "Message Components!",
components: [
new Discord.MessageActionRow().addComponents(
...buttons
),
new Discord.MessageActionRow().addComponents(
...buttons.map(button => {
button = new Discord.MessageButton(button).setDisabled();
if (button.customId) {
button.setCustomId(button.customId+"'");
}
return button;
})
),
new Discord.MessageActionRow().addComponents(
new Discord.MessageButton().setStyle("SECONDARY").setCustomId("label and emoji").setLabel("Label and emoji").setEmoji("🚀"),
new Discord.MessageButton().setStyle("SECONDARY").setCustomId("label only").setLabel("Label only"),
new Discord.MessageButton().setStyle("SECONDARY").setCustomId("emoji only").setEmoji("🚀"),
),
new Discord.MessageActionRow()
.addComponents(
new Discord.MessageSelectMenu()
.setCustomId("SelectMenu-Disabled")
.setPlaceholder("Disabled SelectMenu")
.setDisabled(true)
.setMinValues(1)
.setMaxValues(3)
.addOptions({
label: "リンゴ",
value: "apple",
emoji: "🍎"
}, {
label: "ミカン",
value: "orange",
emoji: "🍊"
}, {
label: "バナナ",
value: "banana",
emoji: "🍌"
})
),
new Discord.MessageActionRow()
.addComponents(
new Discord.MessageSelectMenu()
.setCustomId("SelectMenu-Active")
.setPlaceholder("Active SelectMenu")
.setMinValues(1)
.setMaxValues(3)
.addOptions({
label: "リンゴ",
value: "apple",
default: true,
emoji: "🍎"
}, {
label: "ミカン",
value: "orange",
default: true,
emoji: "🍊"
}, {
label: "バナナ",
value: "banana",
emoji: "🍌"
})
),
]
});
}
main();