在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):discordjs/discord.js开源软件地址(OpenSource Url):https://github.com/discordjs/discord.js开源编程语言(OpenSource Language):JavaScript 56.3%开源软件介绍(OpenSource Introduction):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 discord.js: npm install discord.js
yarn add discord.js
pnpm add discord.js Register a slash command against the Discord API: const { REST, 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.applicationCommands(CLIENT_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
请发表评论