Send a message with Discord.js(使用 Discord.js 发送消息)
问题描述
我正在尝试制作一个不和谐的机器人,但我不太了解 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 发送消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 Discord.js 发送消息


基础教程推荐
- 如何添加到目前为止的天数? 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01