mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 08:03:30 +01:00
added examples
This commit is contained in:
16
examples/avatar.js
Normal file
16
examples/avatar.js
Normal file
@@ -0,0 +1,16 @@
|
||||
var Discord = require( "discord.js" );
|
||||
var myBot = new Discord.Client();
|
||||
|
||||
myBot.login( "hello@example.com", "password1" );
|
||||
|
||||
myBot.on( "message", function( message ) {
|
||||
if ( message.content === "$avatar" ) {
|
||||
var user = message.author; //the user who wants an avatar is the author
|
||||
if ( user.avatar ) {
|
||||
var url = "https://discordapp.com/api/users/" + user.id + "/avatars/" + user.avatar + ".jpg";
|
||||
bot.sendMessage( message.channel, message.author.mention() + ", here's your avatar: " + url );
|
||||
} else {
|
||||
bot.sendMessage( message.channel, message.author.mention() + ", you don't have an avatar!" );
|
||||
}
|
||||
}
|
||||
} );
|
||||
10
examples/pingpong.js
Normal file
10
examples/pingpong.js
Normal file
@@ -0,0 +1,10 @@
|
||||
var Discord = require( "discord.js" );
|
||||
var myBot = new Discord.Client();
|
||||
|
||||
myBot.login( "hello@example.com", "password1" );
|
||||
|
||||
myBot.on( "message", function( message ) {
|
||||
if ( message.content === "ping" ) {
|
||||
this.sendMessage( message.channel, "pong" );
|
||||
}
|
||||
} );
|
||||
8
examples/presence.js
Normal file
8
examples/presence.js
Normal file
@@ -0,0 +1,8 @@
|
||||
var Discord = require( "discord.js" );
|
||||
var myBot = new Discord.Client();
|
||||
|
||||
myBot.login( "hello@example.com", "password1" );
|
||||
|
||||
myBot.on( "presence", function( user, status, server ) {
|
||||
bot.sendMessage( server.getDefaultChannel(), user.mention() + " is " + status + "!" );
|
||||
} );
|
||||
Reference in New Issue
Block a user