mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 20:13:30 +01:00
Moar doc examples (#490)
* Add more examples to docs * docs * Switch to objects from resolvables * Small changes in wording
This commit is contained in:
committed by
abalabahaha
parent
4f713a3f6d
commit
461e5b337e
@@ -70,3 +70,40 @@ Here we will demonstrate receiving messages and logging them to the console.
|
|||||||
console.log('(${message.server.name} / ${message.channel.name}) ${message.author.name}: ${message.content}');
|
console.log('(${message.server.name} / ${message.channel.name}) ${message.author.name}: ${message.content}');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Sending messages
|
||||||
|
-----------------
|
||||||
|
|
||||||
|
Sends Hello to "general" in "my_server".
|
||||||
|
|
||||||
|
.. code-block:: javascript
|
||||||
|
|
||||||
|
var channel = client.servers.get("name", "my_server").channels.get("name", "general");
|
||||||
|
client.sendMessage(channel, "Hello");
|
||||||
|
|
||||||
|
You can also use a `Message`_ object as an parameter. This example sends "Hello" to the channel the message was sent from.
|
||||||
|
|
||||||
|
.. code-block:: javascript
|
||||||
|
|
||||||
|
client.on('message', function(message) {
|
||||||
|
client.sendMessage(message, "Hello");
|
||||||
|
});
|
||||||
|
|
||||||
|
You can send DMs to a user with a `User`_ object. This will send "Hello" as an DM to the author of the received message.
|
||||||
|
|
||||||
|
.. code-block:: javascript
|
||||||
|
|
||||||
|
client.on('message', function(message) {
|
||||||
|
client.sendMessage(message.author, "Hello");
|
||||||
|
});
|
||||||
|
|
||||||
|
Replying to messages
|
||||||
|
------------------
|
||||||
|
|
||||||
|
Sends "@author Hello!".
|
||||||
|
|
||||||
|
.. code-block:: javascript
|
||||||
|
|
||||||
|
client.on('message', function(message) {
|
||||||
|
client.reply(message, 'Hello!');
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user