Is it possible to send multiple RichEmbeds in a single message - discord

In the documentation, it states that a Message can have an array of Embeds.
This obviously makes one question if it's possible to send multiple RichEmbed with a single message.
The normal way to send an Embed is to use a MessageOptions Object, like this:
message.channel.send({embed: embedName});
Although this doesn't seem to allow for a multiple of RichEmbeds, does anyone know if it's possible to send multiple?

As Abz6is pointed out, you can post multiple RichEmbeds at once by using a Webhook.
Here is the documentation for the WebhookMessageOptions.
Quick example:
message.channel.createWebhook('Webhook Name', message.author.displayAvatarURL)
.then(w => w.send({embeds: [
new Discord.RichEmbed().setAuthor('Embed 1'),
new Discord.RichEmbed().setAuthor('Embed 2'),
]}));
This works for up to 10 embeds.

Yes! it is Possible to do this, by doing
if(message.content.startswith(Anything)) {
message.channel.send({embed: embedName});
message.channel.send({embed: embedName});
}
Caltrop's Answer also Works.

Related

HOW TO IGNORE DUPLICATES with laravel?

I'm working on reactJs with laravel CHAT. I want to display juste the last message from the sender. But I usually get all his messages. I tried lot of attempts But I didn't get the solution yet. this is my last attempt:
$types= chat::select('id','senderId')->where('userId', $id)->get();
foreach ($types as $chats) {
$chats->chat = chat::select('id','unseenMsgs', 'senderId')->where('senderId', $chats->senderId)
->get();
foreach ($chats->chat as $child){
$child->lastMessage = chat::select('userId','message', 'time', 'senderId')
->where('id', $child->id)
->orderBy('id', 'asc')->skip(0)->take(1)
->get();
}
}
return ['chatsContacts' => $types];
The userId is the receiver one and senderId is the one who send the message. At first query I tried to get all the messages that are sent to the reciever. The question is how to ignore the duplication and get juste the last message from the sender one. and Thanks in advance for your help
Ps: I'm using An MVP and the reponse should be like this:
this picture is for the response in the MVP
That's why in my server side I should create an api which return exactly this response
It is hard to recreate the issue with the amount of information provided.
From what I understand about the problem description, following seems like a possible solution:
$latestChats = chat::select('id', 'userId', 'message', 'time', 'senderId')
->where('userId', $id)
->orderBy('id', 'desc')
->get()
->unique('senderId');
return ['chatsContacts' => $latestChats];
This should give you a collection containing the last messages sent by every senderId to the specified userId.
If this does not resolve your issue please provide further information.
What does the table look like?
What is the exact format you're looking for in chatContacts ?

Mongoose: (CastError) Cast to [ObjectId] failed for value

I'm having a lil problem I've been trying to solve for a while and despite looking online pretty much everywhere I can't find the solution to my problem.
I have 2 mongoose schemas. One "Post" schema and one "Tag" schema.
const postSchema = new Schema({
creator:{type:mongoose.Types.ObjectId, required:true, ref:'User'},
type:{type:String, required:true},
title:{type:String, maxlength:14},
description:{type:String, maxlength:1140},
content:{type:String},
tags:[{type:mongoose.Types.ObjectId, ref:'Tag'}],
date:{type:Date},
});
const tagSchema = new Schema({
name:{type:String, required:true, unique:true},
bgImages:[{type:String}],
posts:[{type:mongoose.Types.ObjectId, ref:'Post'}],
});
When I create a new post, I want to be able to add multiple tags to the tags array in the Post, so what I tried doing is find the ID's of the tags selected by the user and send the array of id's in the POST request.
This is the exact error I get:
'tags.0': CastError: Cast to [ObjectId] failed for value "["60d193ab04caf9336cc9169b,60d193b504caf9336cc9169c"]" (type string) at path "tags.0"
Both the ID's exist in the Tag collection. If I send only one Id in the request it works, but if I send an array of Id's it doesn't.
Something I have in mind is that it sends an array of a single string from what looks like, instead of an array of strings (where each string is the ID).
Can someone help me figure out what's the issue? Thanks a lot.
Found the problem. As I thought it's because I was sending an array containing one single string instead of an array of atomic strings.
Had to split the array with "," to solve the problem.

Trying to do a dm command with msg.mentions.users.first, but it's not working

if(msg.content.startsWith("&%walcome")){
const mentionid = bot.users.cache.get(`${msg.mentions.users.first().id}`)
const up = new Discord.MessageEmbed()
.setColor('#C8CAF9')
.setTitle('Sup')
.setThumbnail(`${msg.mentions.users.first().displayAvatarURL()}`)
.setDescription(`Sup **${msg.mentions.user.first().tag}**, be welcome to MFPA Official Discord Community. If you joined withouht knowing wth is this server, I will explain: this is the official server of the series with the same new, that is available on youtube (https://www.youtube.com/channel/UCWZRrkidNF5Se8fkgGzoxgg)`)
.addFields(
{name: 'Fun in server', value: 'That is right, dear new member, you can actually have fun in this channel! We have some custom emojis, events, chat (sometimes is dead but eh-). But!, first of all, do not forget to go to #verify (823564914605686844) to get access to the server'},
{name: 'Specific Announcements', value: 'You can receive specific announcements (Faded Pics, Betro Ideas and Dani Sounds) if you are interested in the whole production of the series'},
{name: 'If you need help, just dm a staff member', value: 'Thats right, if you need help, you can contact one of the Staff Team member, they will reply when available'}
)
.setFooter(`Sent by ${msg.author.tag}, bot made by dani bear#3606`, `${msg.author.displayAvatarURL()}`)
mentionid.send(up)
}
})
So, this code is not working, and I don't know why. The error is Cannot read property 'first' of undefined, but I already used this and it worked-
If you could help I would be grateful!
You have a typo in .setDescription('Sup **${msg.mentions.user.first().tag...)}'.Its msg.mentions.users.first()(Missed an 's' in 'users'). Also, if you are going to use the mentioned User object again and again, store then in a variable, and then access the properties of that.

Laravel 4 not getting JSON from input Backbone.js

I have read and worked with the other posts about this and it appears the version of Laravel 4 I just downloaded has more changes made to the way the JSON input is handled by a controller.
$input = Input::json()->all(); gives me errors as if I am referring to something that does not exist when I request some part of the payload after doing a PUT request. And without ->all(); I get a symfony error.
Does anyone know how to get good JSON from backbone in Laravel 4's latest version?
Currently, I am doing the long way around to get my data, ie:
$input_title = Input::get('title');
$input_completed = Input::get('completed');
$task = Task::find($id);
$task->title = $input_title;
$task->completed = $input_completed;
$task->save();
Yes, I am doing the tutorial on tutsplus to learn laravel/backbone, so a little noob patience is apreciated.
The error I get when using Input::get(); is:
{"error":{"type":"UnexpectedValueException","message":"The Response content must be a string or object implementing __toString(), \"array\" given.","file":"/Users/brentlawson23/Sites/laravel4App/bootstrap/compiled.php","line":16858}}
I really want to get the Laravel-specific answer instead of using straight php to stringify the payload.
I get same error using just Input::json();
For the current beta of Laravel 4, Input::json(); is not getting a stringified version of the request payload that can be used to create a new row in a table, nor does Input::json()->all(); (hoping to play nice with the ParameterBag from symfony). I have tried json_encode among other hacks and basically every step of the way in this tut, I hit some brick wall. Anyone have a suggestion based on what I have presented here?
Today I got this when simply trying to echo the result of $input = Input::json(); :
{"error":{"type":"ErrorException","message":"Catchable Fatal Error: Object of class Symfony\Component\HttpFoundation\ParameterBag could not be converted to string in /Users/brentlawson23/Sites/laravel4App/app/controllers/TasksController.php line 45","file":"/Users/brentlawson23/Sites/laravel4App/app/controllers/TasksController.php","line":45}}
Yes, I have studied the Symfony API.
I had a similar problem. Input from Backbone is converted to array in Laravel. On tutsplus, Jeffrey Way is using object. So I was trying to do this (like in tutorial):
return $input->title // using object,but got an error.
If I change that line to:
return $input["title"] // everything works fine with array.
I'm also working through the Backbone tutorial on tuts+. If I'm right in assuming are you stuck on the Creating New Contacts section? Below is how I got it to work for me, in ContactController.php:
public function store()
{
$input = Input::all();
Contact::create(array(
'first_name' => $input['first_name'],
'last_name' => $input['last_name'],
'email_address' => $input['email_address'],
'description' => $input['description']
));
}
And then also needed to update app/models/Contact.php with the below:
class Contact extends Eloquent {
protected $fillable = array('first_name', 'last_name', 'email_address', 'description');
}
That should get it working for you and insert the contact into the database. If I've misread let me know and I can have another look.
Cheers,
Sean

How to set up CakePHP 2.x to behave like a RESTful webservices (for using it together with JavascriptMVC)

I am trying to set up cakephp to work with the very nice javascriptMVC (http://forum.javascriptmvc.com). JavaScriptMVC requires the JSON-Output in the following format:
[{
'id': 1,
'name' : 'Justin Meyer',
'birthday': '1982-10-20'
},
{
'id': 2,
'name' : 'Brian Moschel',
'birthday': '1983-11-10'
}]
Cake would generate a deeper nested array with a prepended Class Name. I found attempts to solve the problem but theyre not for cakephp 2.x. I know that I can simply generate a new array and json_encode() it via php, but it would be nicer to include a function like this https://gist.github.com/1874366 and another one to deflatten it.
Where would be the best place to put such functions? The AppController doesnt seem to work. Should i put it in beforeRender () or beforeFilter() of the controller? Or does someone maybe even know of an existing solution/plugin for this? This would be the best for me in my current Situation, as Im pretty much pressed for time.
Ok, I'm not 100% sure I understand what you are trying to do so here's a word to the wise just in case: Cake and JMVC are both comprehensive MVC frameworks. if you are attempting to combine them as a single cohesive platform to build your application, I strongly suggest you review your approach / platform / etc.
Also -- I'm not an expert by any means in jmvc, so I'm just going to pretend that processing the response from Cake in jmvc is completely out of the question, for some odd reason. For the record, think of Cake's responses like this:
{ "Model" :
[{
'id': 1,
'name' : 'Justin Meyer',
'birthday': '1982-10-20'
},
{
'id': 2,
'name' : 'Brian Moschel',
'birthday': '1983-11-10'
}]
}
Cake has had comprehensive REST service support, since at least Cake 1.2. The lib you are interested in is HttpSocket. As for json encoding and serving response, Request Handling covers, among other things, responding to all manners of requests, content types, decoding and encoding json, etc. Finally, the built-in Set utility will almost certainly cover whatever array manipulation you need in a line or two.
The functionality you are interested in is pretty basic and hasn't changed too much. I'd bet a lot of the (reasonably simple) solutions you have already found would probably still work, maybe with a little bit of tweaking.
For pretty much any basic service endpoint, you would probably create a controller (not AppController - that is application-wide, hence you can't invoke it directly) method, considering Cake routes the controller/action into your url:
Cake consuming services from a different app would look like this:
http://cakeproject/collect/getInfo
class CollectController extends AppController {
public function getInfo($array = null) {
App::uses('HttpSocket', 'Network/Http');
$http = new HttpSocket();
$http->get('http://jmvcproject/controller/action', $array);
// ...etc.
}
Cake providing services from the same controller / action to a different app would simply be:
public function getInfo($array = null) {
$results = $this->Collect->find('all', $array);
// ...fetch the results
}
Or you could just loop over that array with foreach($this->data as $data) { ... to drop the class name. But if your data will include associated models, etc, Set is probably the most versatile and resilient solution.
Anyway, HTH

Resources