INTERACTIONS
Slash commands
Registering slash commands
https://discordjs.guide/interactions/slash-commands.html#registering-slash-commands
Follow-ups
์ฌ๋ฌ๊ฐ ์๋ต์ ์ํ ๊ฒฝ์ฐ ์ฌ์ฉ!
์ด๊ธฐ ์๋ต ํ interaction ํ ํฐ์ 15๋ถ ๋์ ์ ํจํจ
ephemeral: true -> command ์คํ์๋ง ์๋ต ๋ฐ๊ธฐ
client.on('interactionCreate', async interaction => {
if (!interaction.isCommand()) return;
if (interaction.commandName === 'ping') {
await interaction.reply('Pong!');
await interaction.followUp({ content: 'Pong again!', ephemeral: true });
}
});
Fetching and deleting responses
ephemeral message๋ ์ญ์ ๋ถ๊ฐ๋ฅ
await interaction.reply('Pong!');
await interaction.deleteReply();
๋ฐ์ ์ถ๊ฐ ๋ฑ ๋ค์ํ ์ด์ ๋ก ์๋ต์ Message ๊ฐ์ฒด๊ฐ ํ์ํ ์ ์๋ค. fetchReply() ๋ฉ์๋๋ฅผ ์ฌ์ฉํ์ฌ ์ด๊ธฐ reply์ Message ์ธ์คํด์ค๋ฅผ ๊ฐ์ ธ์ฌ ์ ์๋ค.
await interaction.reply('Pong!');
const message = await interaction.fetchReply();
console.log(message);
DM permission
setDMPermission ๋ฉ์๋๋ฅผ ์ฌ์ฉํ์ฌ DM์์ global command๋ฅผ ์ฌ์ฉํ ์ ์๋์ง ์ฌ๋ถ๋ฅผ ์ ์ดํ ์ ์๋ค. ๊ธฐ๋ณธ์ ์ผ๋ก ๋ชจ๋ global command๋ DM์์ ์ฌ์ฉํ ์ ์๋ค.
const { SlashCommandBuilder } = require('@discordjs/builders');
const data = new SlashCommandBuilder()
.setName('boop')
.setDescription('Replies with beep!')
.setDMPermission(false);
Member permissions
setDefaultMemberPermissions ๋ฉ์๋๋ฅผ ์ฌ์ฉํ์ฌ ๊ตฌ์ฑ์์ด command๋ฅผ ์คํํ๋ ๋ฐ ํ์ํ ๊ธฐ๋ณธ ๊ถํ์ ์ค์ ํ ์ ์๋ค. ์ด ๊ฐ์ 0์ผ๋ก ์ค์ ํ๋ฉด ํน์ ๋ฎ์ด์ฐ๊ธฐ๊ฐ ๊ตฌ์ฑ๋๊ฑฐ๋ ์ฌ์ฉ์์๊ฒ ๊ด๋ฆฌ์ ๊ถํ์ด ์๋ ํ ๊ธธ๋์ ๋ชจ๋ ์ฌ๋์ด command๋ฅผ ์ฌ์ฉํ ์ ์๋ค.
const { SlashCommandBuilder } = require('@discordjs/builders');
const { PermissionFlagsBits } = require('discord-api-types/v10');
const data = new SlashCommandBuilder()
.setName('ban')
.setDescription('Ban a member!')
.addUserOption(option =>
option.setName('target').setDescription('The member to ban'))
.setDefaultMemberPermissions(PermissionFlagsBits.KickMembers | PermissionFlagsBits.BanMembers);
'Bot > Discord Bot' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Discord.py] Bookmarks (0) | 2022.08.01 |
---|---|
discord.js bot ๋ง๋ค๊ธฐ (2) - Events (0) | 2022.07.13 |
discord.js bot ๋ง๋ค๊ธฐ (1) (0) | 2022.07.13 |