Skip to content

Instantly share code, notes, and snippets.

@hepteract
Last active November 29, 2022 05:06
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save hepteract/8d9199a6a154dd32a1c4ced97de76043 to your computer and use it in GitHub Desktop.
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);
}
@Tsa6
Copy link

Tsa6 commented Aug 16, 2017

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.

@Joviverde
Copy link

How i use this?

@Kuju29
Copy link

Kuju29 commented Nov 5, 2017

Does it still work normally? With me it does not work

@VeH-c
Copy link

VeH-c commented Feb 22, 2018

i have found one that works(as of posting), also it grabs your Security Token for you 🥇

@EastArctica
Copy link

i have found one that works(as of posting), also it grabs your Security Token for you

doesnt work anymore

@Fraserbc
Copy link

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

@Gianni0177
Copy link

Gianni0177 commented Oct 26, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment