Created
April 22, 2017 18:54
-
-
Save 1Conan/83a802a21bdae7ab1029e95b9723c240 to your computer and use it in GitHub Desktop.
Just a simple toy client to speak as a bot.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script src='discord.11.0.0.js'></script> | |
</head> | |
<body> | |
<div id='msgDiv' style='display:none'> | |
<ul id='msgs' style="overflow:scroll; height:400px;"> | |
</ul> | |
<input type="text" id="message" placeholder="message here"> | |
</div> | |
<div id='loginDiv'> | |
<input type="text" id="channel" placeholder="channel id here"><br> | |
<input type="text" id="token" placeholder="token here"><br> | |
<button id='login'>Login</button> | |
</div> | |
<script> | |
var token = ''; | |
var channelid = ''; | |
var loggedin = false; | |
var Discord = window.Discord; | |
var client = new Discord.Client(); | |
document.getElementById('login').onclick = function() { | |
token = document.getElementById('token').value; | |
channelid = document.getElementById('channel').value; | |
client.login(token) | |
console.log('logging in'); | |
loggedin = true; | |
document.getElementById('msgDiv').removeAttribute('style'); | |
document.getElementById('loginDiv').setAttribute('style', 'display:none'); | |
} | |
document.addEventListener('keydown', function(event) { | |
if(loggedin === true && event.keyCode == 13) { | |
client.channels.get(channelid).sendMessage(document.getElementById('message').value) | |
document.getElementById('message').value = ''; | |
} | |
},false); | |
client.on('ready', function() { | |
console.log('ready') | |
}); | |
client.on('message', function(msg) { | |
if(msg.channel.id !== channelid) return; | |
console.log('msg received!'); | |
var el = document.createElement('li'); | |
el.appendChild(document.createTextNode(msg.member.displayName + ': ' + msg.content)); | |
document.getElementById('msgs').appendChild(el); | |
var e = document.getElementById("msgs"); | |
e.scrollTop = e.scrollHeight; | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment