-
-
Save hepteract/8d9199a6a154dd32a1c4ced97de76043 to your computer and use it in GitHub Desktop.
//META{"name":"SendEmbeds"}*// | |
function SendEmbeds() { | |
return; | |
} | |
SendEmbeds.prototype.load = function() {}; | |
SendEmbeds.prototype.unload = function() {}; | |
SendEmbeds.prototype.start = function() { | |
this.attachHandler(); | |
}; | |
SendEmbeds.prototype.onSwitch = function() { | |
this.attachHandler(); | |
}; | |
SendEmbeds.prototype.stop = function() { | |
var el = $('.channel-textarea textarea'); | |
if (el.length == 0) return; | |
// Remove handlers and injected script | |
el.unbind("click focus", this.focusHandler); | |
el[0].removeEventListener("keydown", this.handleKeypress); | |
}; | |
SendEmbeds.prototype.getName = function() { | |
return "Send Embeds"; | |
}; | |
SendEmbeds.prototype.getDescription = function() { | |
return "Allows you to create fancy embed text."; | |
}; | |
SendEmbeds.prototype.getVersion = function() { | |
return "0.1"; | |
}; | |
SendEmbeds.prototype.getAuthor = function() { | |
return "Septeract"; | |
}; | |
var token = "PUT YOUR TOKEN HERE"; // Have to do this because localStorage.token no longer works | |
let sendEmbed = function(title, text, color) { | |
var channelID = window.location.pathname.split('/').pop(); | |
var embed = { | |
type : "rich", | |
description : text | |
}; | |
if (color) { | |
embed.color = color; | |
} | |
if (title) { | |
embed.title = title; | |
} | |
var data = JSON.stringify({embed : embed}); | |
console.log(data); | |
$.ajax({ | |
type : "POST", | |
url : "https://discordapp.com/api/channels/" + channelID + "/messages", | |
headers : { | |
//"authorization": localStorage.token.slice(1, -1) | |
"authorization": token | |
}, | |
dataType : "json", | |
contentType : "application/json", | |
data: data, | |
error: (req, error, exception) => { | |
console.log(req.responseText); | |
} | |
}); | |
} | |
SendEmbeds.prototype.attachHandler = function() { | |
var el = $('.channel-textarea textarea'); | |
if (el.length == 0) return; | |
var self = this; | |
// Handler to catch key events | |
this.handleKeypress = function (e) { | |
var code = e.keyCode || e.which; | |
if (code !== 13) { | |
// console.log(`Ignored keypress: ${code}`); | |
return; | |
} | |
var text = $(this).val(); | |
if (!text.startsWith("/e")) { | |
// console.log(`Ignored text entry: ${text}`); | |
return; | |
} | |
e.preventDefault(); | |
e.stopPropagation(); | |
var color; | |
var msg; | |
if (text[3] == "#") { | |
color = parseInt(text.slice(4, 10), 16); | |
msg = text.substring(11); | |
} else { | |
msg = text.substring(3); | |
} | |
var title; | |
if (msg[0] == "\"") { | |
msg = msg.substring(1); | |
let index = msg.indexOf("\""); | |
title = msg.substring(0, index); | |
msg = msg.substring(index + 2); | |
} | |
sendEmbed(title, msg, color); | |
$(this).val(""); | |
} | |
// bind handlers | |
el[0].addEventListener("keydown", this.handleKeypress, false); | |
} |
I just installed, and was having problems with the plugin not recognizing it's command. I poked around a bit and found that the query selector on line 82 (var el = $('.channel-textarea textarea');
) wasn't targeting the message box correctly so the event listener wasn't bound correctly. I changed it to .channel-text-area-default textarea
, and now everything works. Running Discord 7.21.16 with BetterDiscord 0.2.82 on ArchLinux.
Also, for future readers, installation requires replacing PUT YOUR TOKEN HERE
(ln 44) with your discord token, and then the command syntax is /e #ffffff "Title" Message
replacing the values as necessary.
How i use this?
Does it still work normally? With me it does not work
i have found one that works(as of posting), also it grabs your Security Token for you 🥇
i have found one that works(as of posting), also it grabs your Security Token for you
doesnt work anymore
Here is a version I have fixed. If it doesn't work just create an issue and I will try my best to fix it.
https://github.com/Fraserbc/BetterDiscord-Embeds
I don't know why it doesn't work.
If i press enter it doesn't appear anything even if I use the example code
I've got a problem with this plugin.
While preparing an embed with
/e
, I tried to move to the next line with Shift + Enter... but my message was sent immediately rather than just jumping to next line.