在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:discordjs/discord.js开源软件地址:https://github.com/discordjs/discord.js开源编程语言:JavaScript 60.5%开源软件介绍:Aboutdiscord.js is a powerful Node.js module that allows you to easily interact with the Discord API.
InstallationNode.js 16.9.0 or newer is required. npm install discord.js
yarn add discord.js
pnpm add discord.js Optional packages
Example usageInstall all required dependencies: npm install discord.js @discordjs/rest
yarn add discord.js @discordjs/rest
pnpm add discord.js @discordjs/rest Register a slash command against the Discord API: const { REST } = require('@discordjs/rest');
const { Routes } = require('discord.js');
const commands = [
{
name: 'ping',
description: 'Replies with Pong!',
},
];
const rest = new REST({ version: '10' }).setToken('token');
(async () => {
try {
console.log('Started refreshing application (/) commands.');
await rest.put(Routes.applicationGuildCommands(CLIENT_ID, GUILD_ID), { body: commands });
console.log('Successfully reloaded application (/) commands.');
} catch (error) {
console.error(error);
}
})(); Afterwards we can create a quite simple example bot: const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('interactionCreate', async (interaction) => {
if (!interaction.isChatInputCommand()) return;
if (interaction.commandName === 'ping') {
await interaction.reply('Pong!');
}
});
client.login('token'); Links
ExtensionsContributingBefore creating an issue, please ensure that it hasn't already been reported/suggested, and double-check the
documentation. HelpIf you don't understand something in the documentation, you are experiencing problems, or you just need a gentle nudge in the right direction, please don't hesitate to join our official discord.js Server. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论