mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
Basic fixes, added test script
This commit is contained in:
105
test/bot.1.js
105
test/bot.1.js
@@ -1,69 +1,52 @@
|
||||
var Discord = require("../");
|
||||
var Member = require("../lib/Member.js");
|
||||
var mybot = new Discord.Client({
|
||||
compress : true,
|
||||
catchup : "all"
|
||||
});
|
||||
var fs = require("fs");
|
||||
var request = require("request").defaults({ encoding: null });
|
||||
|
||||
Discord.patchStrings();
|
||||
|
||||
var server, channel, message, sentMessage = false;
|
||||
|
||||
mybot.on("message", function (message) {
|
||||
|
||||
console.log("Everyone mentioned? " + doned);
|
||||
doned++;
|
||||
if (message.content.substr(0, 3) !== "$$$") {
|
||||
return;
|
||||
}
|
||||
|
||||
// we can go ahead :)
|
||||
|
||||
var user;
|
||||
if (message.mentions.length > 0) {
|
||||
user = message.mentions[0];
|
||||
} else {
|
||||
user = message.sender;
|
||||
}
|
||||
|
||||
mybot.reply(message, "Hello! It has been " + ((Date.now() - message.timestamp) - this.timeoffset) + "ms since you sent that.");
|
||||
});
|
||||
|
||||
var doned = 0;
|
||||
|
||||
mybot.once("ready", function () {
|
||||
console.log("im ready");
|
||||
|
||||
for (var server of mybot.servers) {
|
||||
if (server.name === "test-server") {
|
||||
mybot.leaveServer(server);
|
||||
var client = new Discord.Client();
|
||||
client.on("debug", (m) => console.log("[debug]",m));
|
||||
client.on("warn", (m) => console.log("[warn]", m));
|
||||
var start = Date.now();
|
||||
client.on("message", m => {
|
||||
if(m.content === "&init"){
|
||||
for(var channel of m.channel.server.channels){
|
||||
if(channel instanceof Discord.VoiceChannel){
|
||||
client.joinVoiceChannel(channel).catch(error)
|
||||
.then(connection => {
|
||||
connection.playFile("C:/users/amish/desktop/Developers.mp3");
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(m.content.startsWith("$$$ stop")){
|
||||
for(var channel of m.channel.server.channels){
|
||||
if(channel instanceof Discord.VoiceChannel){
|
||||
chan = channel;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(client.internal.voiceConnections.get("id", chan.id)){
|
||||
var connection = client.internal.voiceConnections.get("id", chan.id);
|
||||
connection.stopPlaying();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if(m.content.startsWith("$$$")){
|
||||
var chan;
|
||||
for(var channel of m.channel.server.channels){
|
||||
if(channel instanceof Discord.VoiceChannel){
|
||||
chan = channel;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(client.internal.voiceConnections.get("id", chan.id)){
|
||||
var connection = client.internal.voiceConnections.get("id", chan.id);
|
||||
connection.playFile("C:/users/amish/desktop/Developers.mp3");
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
mybot.on("messageUpdate", function(newMessage, oldMessage){
|
||||
mybot.reply(newMessage, JSON.stringify(newMessage.embeds));
|
||||
})
|
||||
|
||||
mybot.on("serverUpdate", function (oldserver, newserver) {
|
||||
console.log("server changed! " + mybot.servers.length);
|
||||
})
|
||||
|
||||
|
||||
mybot.on("channelUpdate", function (oldChan, newChan) {
|
||||
|
||||
});
|
||||
|
||||
|
||||
function dump(msg) {
|
||||
console.log("dump", msg);
|
||||
function error(e){
|
||||
console.log(e.stack);
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
function error(err) {
|
||||
console.log(err);
|
||||
}
|
||||
|
||||
mybot.login(process.env["ds_email"], process.env["ds_password"]).catch(error);
|
||||
client.login(process.env["discordEmail"], process.env["discordPass"]).catch((e)=>console.log(e));
|
||||
Reference in New Issue
Block a user