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 发送消息


- Fetch API 如何获取响应体? 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- 400或500级别的HTTP响应 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01