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

查看:675
本文介绍了使用Discord.js发送消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此。我正在尝试制作一个不和谐机器人,但我不太了解Discord.js。
我的代码如下所示:

So. 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.

任何人都可以帮助我吗?

Can anybody help me ?

推荐答案

你的<$ c中有错误$ c> .send()行。您拥有的当前代码在早期版本的discord.js库中使用,并且发送功能已更改。

You have an error in your .send() line. The current code that you have is used in an earlier version of the discord.js library, and the send function has been changed.

要发送消息,请使用此行:

To send a message, use this line:

message.channel.send('My Message')

如果您收到错误消息消息未定义 ,确保已将该行放入消息事件处理程序中。

If you get an error saying that message is not defined, make sure that you have put the line in your message event handler.

client.on("message", function(message) {
  //message sending goes here
});

您还可以向特定频道发送消息,您可以请使用以下行。

You can also send a message to a specific channel, which you can do using the line below.

client.channels.get(channelID).send('My Message');

或者如果你愿意的话,公会的默认频道(公会时的#general频道)已创建)

Or if you prefer, a guild's default channel (the #general channel that was made when the guild was created)

guildObj.defaultChannel.send('My Message');

希望这会有所帮助,

- 间谍

这篇关于使用Discord.js发送消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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