问题描述
我正在尝试制作一个不和谐的机器人,但我不太了解 Discord.js.我的代码如下所示:
I am trying to make a discord bot, but I can't quite understand Discord.js. My code looks like this:
client.on('message', function(message) {
if (message.content === 'ping') {
client.message.send(author, 'pong');
}
});
问题是我不太明白如何发送消息.
And the problem is that I can't quite understand how to send a message.
谁能帮帮我?
推荐答案
发送码又改了.问题和答案中的项目都已过时.对于版本 12,下面将是正确的代码.有关此代码的详细信息,请参阅此 链接.
The send code has been changed again. Both the items in the question as well as in the answers are all outdated. For version 12, below will be the right code. The details about this code are available in this link.
向特定频道发送消息
const channel = <client>.channels.cache.get('<id>');
channel.send('<content>');
向 DM 中的特定用户发送消息
To send a message to a specific user in DM
const user = <client>.users.cache.get('<id>');
user.send('<content>');
如果你想给用户发私信,请注意机器人和用户应该至少有一个共同的服务器.
If you want to DM a user, please note that the bot and the user should have at least one server in common.
希望这个答案对版本 12 之后来这里的人有所帮助.
Hope this answer helps people who come here after version 12.
这篇关于使用 Discord.js 发送消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!



大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)