I was looking at discord.js documentation and I saw this :
.embeds
A list of embeds in the message - e.g. YouTube Player
Type: Array
"A list" :O ?
That mean it is possible to have several embeds in one message.
I have been looking for a way to do this, but I didn't find anything (I know there is another post on stack overflow about that, but it is inactive and unawsnered)
I took an old code channel.send(this.embed()); and tried to edit it so it send two embeds instead of just one.
this.embed() runs
{
var builder = new Discord.RichEmbed();
builder.setTitle(...);
...
return builder
}
First attempt was
channel.send(this.embed(), this.embed());
send [object Object] then the second embed*
channel.send("", this.embed(), this.embed());
send the first embed*
Then I looked at the doc more about .send :
.send([content] , [options])
Send a message to this channel.
blabla
Example 4
>// Send an embed with a local image inside
>channel.send('This is an embed', {
> embed: {
> thumbnail: {
> url: 'attachment://file.jpg'
> }
> },
> files: [{
> attachment: 'entire/path/to/file.jpg',
> name: 'file.jpg'
> }]
>})
> .then(console.log)
> .catch(console.error);
So I used that example and try to reproduce it for my case.
I tried a lot of differents syntax, and I won't post all the variations ^^'
But I want to show you these two :
channel.send("", {
{embed:this.embed(petit)},
{embed:this.embed(petit)}
}
);
SyntaxError: Unexpected token {
channel.send("", {
embed: [{this.embed(petit), this.embed(petit)}]
} );
SyntaxError: Unexpected token .
etc...
I feel like I get closer to the solution with the last attempts but I'm still missing something.
I really want to have all my embeds in one message, I know I can send them one by one but I don't want that :)
Also is there a maximum amount of embeds in a message ?
Thanks for reading, I hope I didn't made that much typos ^^
Nalfarvi
You can send multiples embedded messages with this syntax:
channel.send({
embed: {
// Your embedded message's content
},
embed: {
// Your second embedded message's content
}
})
Related
In the past when I used to send requests to get user's data in JSON format I just did:
https://www.instagram.com/user_name/?__a=1
and it would return me all the data and the first 12 posts(with their picture's link)
but now it is just returning:
for (;;);
{
"__ar":1,
"error":1357004,
"errorSummary":"Sorry, something went wrong",
"errorDescription":"Please try closing and re-opening your browser window.",
"payload":null,
"hsrp":
{
"hblp":
{
"consistency":
{
"rev":1005869239
}
}
},
"lid":"7122014805466860625"
}
for some weird reason, and my app is not working anymore because of that, does someone have an idea how to fix that?
Situation: 3rd Party Discord Bot sends masked URL in case of certain events into a private discord channel as an embedded message, instead of clicking on them manually the goal is to have another bot opening those hyperlinks automatically.
Current Status: With a lot of research (also on stack overflow) I managed to get to the following state that will open hyperlinks that are sent as normal text in the respective discord channel or that are included in the description of an embedded message (Kudos to Zach C & Daemon Beast):
client.on("message", message => {
if (message.channel.id == config.channelIds) {
//first part analyses normal messages
if (message.content.includes("https")) {
var link = message.content.split("https")[1]
console.log(link)
var linktest = `https${link}`
console.log(`opening ${linktest}`)
open(linktest)
}
//second part analyses embeded messsages
else if (message.embeds) {
message.embeds.forEach(embed => {
if (embed.description.includes("https")){
var link = embed.description.split("https")[1];
link = link.replace(")", "");
console.log(link);
var linktest = `https${link}`;
console.log(`opening ${linktest}`);
open(linktest);
}
});
}
}
})
Testing: Testing was done using another Bot sending embedded hyperlinks. When they were embedded in the Body/Description the hyperlinks are being opened just fine.
//Testing Bot:
{"content": null,
"embeds": [
{
"title": "Test Title",
"description": "Test Description",
"color": 2108322,
"fields": [
{
"name": "Test Name",
"value": "Test Value\n[Click here to test](https://google.com)"
}]}]}
Problem: In this particular use case hyperlinks are not included in the body/description but rather in the field value which currently not being recognized by the bot and thus not opened.
I already went tough a couple of hours of research & trial/error but was not able to change the code in a way that it would work.
I have tried to use "some" functionality
if (embed.fields.some(f => f.value.includes("https")))
and "includes"
if(message.content.toLowerCase().includes("https"))
But while with the some functionality I was able to make some progress by getting a return value "true" I struggle in adjusting the "var link =" in a way to then get to a proper link.
I have used the replace function to remove the closing bracket ) from the hyperlink.
I feel like I have reached 95% and there is only a small adjustment necessary that the code actually targets the right fields in the embedded message.
Your support is very much appreciated, thank you in advance!
For the sake of completion I would like to share the found solution, there would be better ones with loops but this one worked for me as the link is always at the same place in the embed:
else if (message.embeds) {
message.embeds.forEach(embed => {
console.log(message.embeds[0].fields[8].value);
if (embed.fields[6].value.includes("https")){
var link = embed.fields[6].value.split("https")[1];
link = link.replace(")", "");
console.log(link);
var linktest = `https${link}`;
console.log(`opening ${linktest}`);
open(linktest);
I am making an application that highlights key words in the current page after the user clicks my icon. I am trying to communicate between my content scripts and background script. However,my code is not working. Does anyone know how it should be written?
Here is my content script:
chrome.extension.onRequest.addListener(function(active,sender,sendResponse){
if(active.length>0){
jQuery(document).ready(function($) {
//rest of word highlighting code
}
})
here is my background.js :
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.extension.sendRequest(active);
});
Do not use the deprecated chrome.extension.sendRequest and matching events. They are old, broken and not supported, which is quite clearly said in the documentation - which shows that you did not go and read it.
The correct ones to use are chrome.runtime.sendMessage and .onMessage, but otherwise the signature is the same.
Well.. Why did you expect that to work? (unless you're not really showing us all relevant code, which is.. not helpful)
chrome.browserAction.onClicked.addListener(function(tab) {
// There is no "active" in the code anywhere to this point.
// It is treated like a variable name, one that was not yet used,
// so its contents are "undefined", and that's what you're sending.
chrome.runtime.sendMessage(active);
// Equivalent code: chrome.runtime.sendMessage(undefined);
});
And on the receiving side:
chrome.runtime.onMessage.addListener(function(active,sender,sendResponse){
// So, here "active" is undefined. It does not have a length
// parameter, and as such causes a fatal exception
// "Cannot read property 'length' of undefined"
// that you might have seen in the console of the page
if(active.length>0){
/* something */
}
})
Whatever you send is usually, but not always, an object (well, it must be JSON-serializable). If you just want to trigger something and not pass any data, there are 2 often-used conventions, either is fine:
Pass command as a value.
// Sender
chrome.runtime.sendMessage({action: "active"});
// Receiver
chrome.runtime.onMessage.addListener(function(message,sender,sendResponse){
if(message.command == "active"){
/* something */
}
// or, useful if you have many different commands:
switch(message.command){
case "active":
/* something */
break;
}
});
Set a boolean in the message:
// Sender
chrome.runtime.sendMessage({active: true});
// Receiver
chrome.runtime.onMessage.addListener(function(message,sender,sendResponse){
if(message.active){
/* something */
}
});
First time, long time...
I am using Ext JS 4.2.2.1144
I have a grid and my query from the server(php) is returning metadata in the form of json that was previously generated when a user decides to realign and resize the columns and then save that information. All of the fields like width, dataIndex, align, and all that are reconfiguring the grid just fine when using the metaChanged function. The problem that I am having is that one of the columns needs to send over the information for a tpl which is actually the location of an image to show. My Json looks like this
{
"totalCount":"2",
"root":"items",
"metaData":
{
"fields":[
{"name":"queryid"},
{"name":"createUser"},
{"name":"subject"},
{"name":"priorityImage"}
],
"columns":[
{
"dataIndex":"queryid",
"width":100,
"text":"Queryid"
},
{
"dataIndex":"createUser",
"width":100,
"text":"Owner",
"align":"center"
},
{
"dataIndex":"subject",
"width":200,
"text":"Subject",
"hidden":true
},
{
"dataIndex":"priorityImage",
"width":70,"text":"Priority",
"hidden":true,
"align":"center",
"xtype":"templatecolumn",
"tpl":['<img src="_images/{priorityImage}" height="20px" width="20px" />']
}
]
},
"items":[
{
"queryid":"1",
"createUser":"1",
"subject":"Here is a new project",
"priorityImage":"orange.png"
},
{
"queryid":"1",
"createUser":"1",
"subject":"SAL Form 4",
"priorityImage":"roundlightPurple.png"
}
]
}
I have tried all kinds of different ways of sending the tpl for this last column but none of them are success. Anybody with any clues on how to accomplish this? The result ends up being the text and not the actually image. If I load the grid directly from the store using the default model, I get the image from the tpl but just not when doing it through metadata. I have tried single quotes, double quotes, no braces, with braces, lol. Im out of ideas to try. Hopefully I am being clear enough. Anyhoo, thanks for any help in advance, this one is really driving my crazy,
thanks,
C5
I have done something similar long time ago when I needed to send renderers (functions) but they always appear as text. At that time I haven't found other way but to scan the received metaData to see if there is a renderer and call eval on the received text to get the function.
Although not a "do this" answer, I hope it helps.
I figured a work around for this although maybe not the most ideal solution it does work.
When sending the tpl to the Server, it actually gets translated from
<img src="_images/{priorityImage}" height="20px" width="20px" /> to
<img src="_images/{priorityImage}" height="20" width="20" />
So here is my fix for now anyway:
Before I call the code to load the store
Ext.getCmp('lblCurrentMetaGrid').setText('projectsGridGrid');
store.on('metachange', metaChanged, this);
Then in the metaChanged function it looks like this:
function metaChanged(store,meta){
var gridname = Ext.getCmp('lblCurrentMetaGrid').text;
var grid = Ext.getCmp(gridname);
for(var c = 0; c < meta.columns.length; c++ ){
var column = meta.columns[c];
var tpl = column.tpl;
if ( tpl !== undefined){
meta.columns[c].tpl[0] = meta.columns[c].tpl[0].replace('<','<');
meta.columns[c].tpl[0] = meta.columns[c].tpl[0].replace('>','>');
meta.columns[c].tpl[0] = meta.columns[c].tpl[0].replace(/\"/g,'"');
}
}
//lets look at all the metadata
grid.reconfigure(store,meta.columns);
}
Now, I am getting my image in the grid.
Is this possible.. here's what I have atm, but my data object is just returning a load of jargon, what am I doing wrong? Am I doing anything.. right, for that matter?
I basically want to print out a list of a users videos (thumbnail and title, and make each one a clickable link to the video itself)
Thanks!
$(document).ready(function(){
$player.init();
})
var $player = (function(){
var player = {};
player.init = function(){
//init Youtube knockout
player.initYoutubeKnockout();
}
player.knockoutModel = {
videoData : ko.observableArray([]),
}
player.initYoutubeKnockout = function()
{
//load the Youtube json feed
$.ajax({
url: 'http://gdata.youtube.com/feeds/api/users/USERNAME/uploads?v=2&alt=json',
type: 'GET',
dataType: 'jsonp',
data: {
count: 5
},
success: function(data, textStatus, xhr) {
player.doYoutubeKnockout(data.item);
}
});
}
player.doYoutubeKnockout = function( data )
{
player.knockoutModel.videoData(data);
ko.applyBindings(player.knockoutModel, $('#youtube-feed')[0]);
console.log($(this));
}
return player;
})();
Frankly you weren't doing much at all.
The JSON data you get back from YouTube is not from data.item, it's in a completely different structure.
I'm assuming you wish to get 5 uploads from the user. The parameter name would be max-results, not count.
Probably the only thing you did fine was set up the url but that's about it.
You need to examine how the JSON returned looks like. Check the API reference for the structure of an atom feed. This is in XML but the corresponding JSON responses will have pretty much the same format with some minor differences. Examine the object by writing it to the console to verify you're getting the right properties.
Once you understand that, you need to use the correct query to get what you're expecting. Check out their API reference on their query parameters.
To help simplify your knockout code, I would strongly recommend you take the response you get back and map it to an object with simplified property names. For instance, to get the thumbnails for an entry, you would have to access the media$group.media$thumbnail array. It would be easier if you can just access it through thumbnail.
Also, if your elements you are binding to need to bind multiple values, it would help to map the values in such a way that your bindings are made easier. For instance, when using the attr binding, you'd set up a property for each of the attributes you want to add. Instead you could just group all the properties in an object and bind to that.
I wrote up a fiddle applying all that I said above to do as you had asked for. This should help give you an idea of what you can do and how to do it.
Demo