問題描述
我正在嘗試制作一個不和諧的機器人,但我不太了解 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');
}
});
問題是我不太明白如何發(fā)送消息.
And the problem is that I can't quite understand how to send a message.
誰能幫幫我?
推薦答案
發(fā)送碼又改了.問題和答案中的項目都已過時.對于版本 12,下面將是正確的代碼.有關(guān)此代碼的詳細信息,請參閱此 鏈接.
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.
向特定頻道發(fā)送消息
const channel = <client>.channels.cache.get('<id>');
channel.send('<content>');
向 DM 中的特定用戶發(fā)送消息
To send a message to a specific user in DM
const user = <client>.users.cache.get('<id>');
user.send('<content>');
如果你想給用戶發(fā)私信,請注意機器人和用戶應(yīng)該至少有一個共同的服務(wù)器.
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.
這篇關(guān)于使用 Discord.js 發(fā)送消息的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!