Calling members roles - discord

I have this code:
guild.members.cache.filter(members => members.roles.cache.get('role_id'))
However, it only returns undefined!

Related

Typescript: Member of union type with incompatible signature when using find on array of objects

I want to check if a value exists in an array of objects.
My array looks something like this:
[
0: {
id: 'unique_obj_id',
item: {
id: 'unique_item_id',
...
},
...
},
1: {...}
]
The objects in the array can be one of many interface types (depending on my api call, here: resource strings represent these interfaces, which are defined somewhere else). But one array will always consist of the same interface types for a given data request.
I'm trying to write a reusable function to check whether given_id exists for any object in the array for obj.item.id.
So far I've managed to write the correct logic but typescript throws some exceptions that I can't seem to figure out. shopApprovalData is a collection of interfaces each following the above object structure accessible by the indices of resource.
export type ApprovalResource = 'str1' | 'str2' | 'str3' | 'str4' | 'str5';
export const checkApprovalItem = (given_id: string, resource: ApprovalResource) => {
const shopApprovalData = useShopApprovals();
if (shopApprovalData && shopApprovalData[resource]) {
const resourceApprovalData = shopApprovalData[resource];
if (resourceApprovalData.find(e => e.item.id === id)) {
return true;
}
}
return false;
}
Typescript shows me that shopApprovalData and itemApprovalData is possibly undefined and that the expression find() is not callable since signatures of members of the union type are not compatible with each other. (Apparently, some removes the error, why?)
What approach should I choose instead to check whether the given_id exists in any object of the array?
Based on your usecase, i create this code sandbox: https://codesandbox.io/s/stackoverflow-answer-ke9drk?file=/src/index.ts
explanation:
Type wont compile, so we need something to mark what the interface of the object.
Also i may confused by your code shopApprovalData[resource] what do you want to achieve here? for example, if resource is str1 shopApprovalData[resource] will always return undefined because no index str1 in Array
I hope it help,
Best Regards

Is it possible to create a 2D array of VlcPlayerController Controller?

List<List<VlcPlayerController>> twoDList = List.generate(3, (i) => List.filled(3, '', growable: false), growable: false);
Is it possible to create a 2D array of VlcPlayerController?
I've tried
The argument type 'String' can't be assigned to the parameter type 'VlcPlayerController'. i get this error message.

Problems with OrmLite query OrderBy method

I am having a few related problems with the OrderBy method when generating a query for OrmLite. The following two statements work:
.OrderBy(ob => new { at = ob.SortBy, ob.Id });
.OrderBy(ob => new { at = Sql.Desc(ob.SortBy), ob.Id });
But the following statement gives me a compile error (Invalid anonymous type member declarator. Anonymous type members must be declared with a member assignment, simple name or member access):
.OrderBy(ob => new { at = Sql.Desc(ob.SortBy), Sql.Desc(ob.Id) });
And the following statement gives me a sql error (Incorrect syntax near the keyword 'ASC'):
.OrderBy(ob => new { at = Sql.Desc(ob.SortBy) });
And when digging deeper I see that the OrderByExpression gives me:
ORDER BY "SortBy" DESC ASC
So... the semi-obvious solution/workaround now that I've been working with OrmLite for a few days is to just concatenate statements and also using OrderByDescending... for example
.OrderByDescending(ob => ob.SortBy).OrderByDescending(ob => ob.Id)
or
.OrderByDescending(ob => ob.SortBy)

AclExtras Warning Error

In CakePHP 2 book / Acl Tutorial / Part 2, I am executing the command:
./Console/cake AclExtras.AclExtras aco_sync
and I get a warning error:
Warning Error: Argument 1 passed to Component::startup() must be an instance of Controller,
null given, called in
/opt/lampp/htdocs/acl/app/Plugin/AclExtras/Console/Command/AclExtrasShell.php
on line 80 and defined in [/opt/lampp/htdocs/acl/lib/Cake/Controller/Component.php, line 119]
The acos table gets populated with NULL in model field and NULL in all fields of the foreign_key.
How can I fix this error?
ThAnKs
in AclExtras/Console/Command, please change startup function to :
public function startup() {
parent::startup();
$controller = new Controller();
$collection = new ComponentCollection();
$this->Acl = new AclComponent($collection);
$this->Acl->startup($controller);
$this->Aco = $this->Acl->Aco;
}

Drupal 7, insert user_profile_form into a page

I tried to insert user_profile_form into a page. the code is rather simple:
global $user;
module_load_include('inc', 'user', 'user.pages');
print drupal_render(drupal_get_form('user_profile_form', $user, 'account'));
everything works fine except when uploading images, it shows:
"Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'user_profile_form' was given in drupal_retrieve_form()"
Any ideas, thx a lot
you need to use form_load_include() instead of module_load_include to load/build a form, and you have to pass arguments inside $form_state.
the code you are looking for looks like:
$form_id = 'user_profile_form';
$form_state = array();
//passing arguments to form.
$form_state['build_info']['args'] = array($account, 'account');
form_load_include($form_state, 'inc', 'user', 'user.pages');
$form = drupal_build_form($form_id, $form_state);
To prevent the notice or warning:
Trying to get property of non-object in user_account_form() (line 1019 of /var/www/modules/user/user.module)
Change the last two lines to:
<?php
$output_form = drupal_get_form($form_id);
print render($output_form);
?>

Resources