@4lch4/discord.js 中文文档教程
@4lch4/discord.js
这是原始 discord.js 仓库的一个分支。 我与该项目的开发人员有个人问题,所以虽然我不想使用他们维护的包,但我会为我的项目设置它。
该文件的其余部分是来自 discord.js 存储库的原始自述文件。
Table of contents
About
discord.js 是一个功能强大的 Node.js 模块,可让您轻松地与 Discord API。
- Object-oriented
- Predictable abstractions
- Performant
- 100% coverage of the Discord API
Installation
需要 Node.js 12.0.0 或更新版本。
忽略任何关于未满足的对等依赖项的警告,因为它们都是可选的。
没有语音支持:npm install discord.js
语音支持 (@discordjs/opus): npm install discord.js @discordjs/opus< /代码
支持语音(opusscript):npm install discord.js opusscript
Audio engines
首选音频引擎是@ discordjs/opus,因为它的性能明显优于 opusscript。 当两者都可用时,discord.js 将自动选择@discordjs/opus。 仅建议在 @discordjs/opus 难以运行的开发环境中使用 opusscript。 对于生产机器人,使用@discordjs/opus 应该被认为是必要的,尤其是当它们要在多个服务器上运行时。
Optional packages
- zlib-sync for WebSocket data compression and inflation (
npm install zlib-sync
) - erlpack for significantly faster WebSocket data (de)serialisation (
npm install discord/erlpack
) - One of the following packages can be installed for faster voice packet encryption and decryption:
- sodium (
npm install sodium
) - libsodium.js (
npm install libsodium-wrappers
) - bufferutil for a much faster WebSocket connection (
npm install bufferutil
) - utf-8-validate in combination with
bufferutil
for much faster WebSocket processing (npm install utf-8-validate
)
Example usage
const Discord = require('discord.js');
const client = new Discord.Client();
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('message', msg => {
if (msg.content === 'ping') {
msg.reply('pong');
}
});
client.login('token');
Links
- Website (source)
- Documentation
- Guide (source) - this is still for stable
See also the Update Guide, including updated and removed items in the library. - Discord.js Discord server
- Discord API Discord server
- GitHub
- NPM
- Related libraries
Extensions
Contributing
在创建问题之前,请确保它尚未被报告/建议,并仔细检查 文档。
如果您想提交 PR,请参阅贡献指南。
Help
如果您不理解文档中的某些内容,您遇到了问题,或者您只需要一个温和的 朝着正确的方向前进,请不要犹豫,加入我们的官方 Discord.js 服务器。
@4lch4/discord.js
This is a fork of the original discord.js repo. I have personal issues with the developers of that project so while I don't want to use their package maintained by them, I'll set this up for my projects.
The remainder of this file is the original README from the discord.js repository.
Table of contents
About
discord.js is a powerful Node.js module that allows you to easily interact with the Discord API.
- Object-oriented
- Predictable abstractions
- Performant
- 100% coverage of the Discord API
Installation
Node.js 12.0.0 or newer is required.
Ignore any warnings about unmet peer dependencies, as they're all optional.
Without voice support: npm install discord.js
With voice support (@discordjs/opus): npm install discord.js @discordjs/opus
With voice support (opusscript): npm install discord.js opusscript
Audio engines
The preferred audio engine is @discordjs/opus, as it performs significantly better than opusscript. When both are available, discord.js will automatically choose @discordjs/opus. Using opusscript is only recommended for development environments where @discordjs/opus is tough to get working. For production bots, using @discordjs/opus should be considered a necessity, especially if they're going to be running on multiple servers.
Optional packages
- zlib-sync for WebSocket data compression and inflation (
npm install zlib-sync
) - erlpack for significantly faster WebSocket data (de)serialisation (
npm install discord/erlpack
) - One of the following packages can be installed for faster voice packet encryption and decryption:
- sodium (
npm install sodium
) - libsodium.js (
npm install libsodium-wrappers
) - bufferutil for a much faster WebSocket connection (
npm install bufferutil
) - utf-8-validate in combination with
bufferutil
for much faster WebSocket processing (npm install utf-8-validate
)
Example usage
const Discord = require('discord.js');
const client = new Discord.Client();
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('message', msg => {
if (msg.content === 'ping') {
msg.reply('pong');
}
});
client.login('token');
Links
- Website (source)
- Documentation
- Guide (source) - this is still for stable
See also the Update Guide, including updated and removed items in the library. - Discord.js Discord server
- Discord API Discord server
- GitHub
- NPM
- Related libraries
Extensions
Contributing
Before creating an issue, please ensure that it hasn't already been reported/suggested, and double-check the documentation.
See the contribution guide if you'd like to submit a PR.
Help
If 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.