使用 Discord.js 发送消息 [英] Send a message with Discord.js

查看:24
本文介绍了使用 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 发送消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆