๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

Bot/Discord Bot

discord.js bot ๋งŒ๋“ค๊ธฐ (3) - Interactions

๋ฐ˜์‘ํ˜•

 

INTERACTIONS

Slash commands

Registering slash commands

 

 

 

 

https://discordjs.guide/interactions/slash-commands.html#registering-slash-commands

 

discord.js Guide

Imagine a guide... that explores the many possibilities for your discord.js bot.

discordjs.guide

 

 

 

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