I want to write in an embed the postion of the role compared to the role position+1 and role position -1 - discord.js

{name:"Position",value: interaction.guild.roles.cache.filter(role.position+1||role.position||role.position-1).map(m=>m).join(" => ")})
i try to map the role position +1 , role position and role position -1.

There are a few issues..
<Collection>#filter's First option is a callback function, not a comparison like you're doing.
Second what you are doing while logically saying "or" makes sense the way node will interpret it is true || true || true as the comparison operator will convert the numeric role position value to a boolean, which if greater than 0 will be true. The proper way to do something like this would be:
interaction.guild.roles.cache.filter(filterRole =>
role.position === filterRole.position - 1 ||
role.position === filterRole.position ||
role.position === filterRole.position + 1
)

Related

Move channel from Category 1 to Category 2 with roles

how do i make the channel move category using roles?
example:
Category 1 (roles 1)
My Channel
Category 2 (roles 2)
as people have pointed out in the comments, this is a really bad question, as stack overflow is for help with issues, not help for writing code. Also try to make your question more descriptive, what have you tried, etc.
It's hard to tell exactly what you mean since the question's less than 20 words long, but moving a channel inside a category should be done like this:
let category = server.channels.cache.find(c => c.name == "My Category" && c.type == "category"),
channel = server.channels.cache.find(c => c.name == "text-channel" && c.type == "text");
if (category && channel) channel.setParent(category.id);

Watson Assistant - How to get size of specific entities

For example I have 3 different entities
#action = eat,run,walk
#person = Michael, John, Fred
#emotion = angry,sad,happy
I want to count user entered action and person entities
If bot recognizes
entities['action'].size() + entities['person'].size() > 2
Any other way to achieve this?
To account for one of the entities not being recognized, you can use ternary operator <Expression> ? <what_to_do_when_true> : <what_to_do_when_false>.
So, in your example the condition would look like this:
((entities['action'] != null ? entities['action'].size() : 0) + (entities['action'] != null ? entities['person'].size() : 0)) > 2
When one of the entity is not recognized (null), the value counted will be 0.

Confusing null compares combined with NOT

I realize that comparing NULL to any other value (including NULL) will always result in false.
DECLARE #IsSet bit = NULL;
SELECT IIF(#IsSet = 1, 'true', 'false')
SELECT IIF(#IsSet != 1, 'true', 'false')
This outputs:
false
false
But this is part that confuses me:
SELECT IIF(NOT(#IsSet = 1), 'true', 'false')
SELECT IIF(NOT(#IsSet != 1), 'true', 'false')
This also outputs:
false
false
I would expect that the NOT would have flipped the value to TRUE. (Which it does if #IsSet is set to 0 for the first expression)
It seems that the compare to the null value has some power over the boolean logic outside the parenthesis.
But the null compare is not all powerful over boolean logic:
SELECT IIF((#IsSet = 1) OR (1=1), 'true', 'false')
SELECT IIF((#IsSet != 1) OR (1=1), 'true', 'false')
This returns:
true
true
I don't understand what is happening here, but I assume that this is done on purpose. But I don't know why.
Can someone explain why NOT(NULL!=1) does not equal true.
A comparison with NULL results in UNKNOWN rather than TRUE or FALSE. NOT UNKNOWN also results in UNKNOWN, which is neither TRUE nor FALSE. One cannot "flip" UNKNOWN to a Boolean value using NOT.
This 3-way logic requires one to use IS NULL or IS NOT NULL to test for NULL values rather than traditional Boolean logic.
The way you are using NOT is not correct. You'll get error, If you only execute the NOT condition as follows:
SELECT NOT(#IsSet = 1)
When you enclose your incorrect usage of NOT condition inside IIF condition, SQL server won't show you the error, However the statement will be evaluated to false output.
If you want to explicitly check for NULL value, then following practice can be adopted.
SELECT IIF(#IsSet IS NULL, 'true', 'false')
Lastly, the following condition is returning 'true' in output, because one of the OR condition (1==1) is always evaluating to 'true', hence the overall output of the IIF statement is true.
SELECT IIF((#IsSet = 1) OR (1=1), 'true', 'false')
SELECT IIF((#IsSet != 1) OR (1=1), 'true', 'false')

ASP.NET MVC 4 MvcMovie Tutorial Filter query by multiple search criteria

I was going through the MvcMovie Tutorial and I was trying to modify the SearchIndex() call in the MoviesController to search by multiple criteria. The tutorial shows you how to search by title and genre using the following code:
var movies = from m in db.Movies
select m;
if (!String.IsNullOrEmpty(searchString))
{
movies = movies.Where(s => s.Title.Contains(searchString));
}
if (string.IsNullOrEmpty(movieGenre))
return View(movies);
else
{
return View(movies.Where(x => x.Genre == movieGenre));
}
So if I read this right they return all movies then filter on Genre. That would be fine for a dual case but when you add in a 3rd or 4th search criteria you would then increase the amount of if statement calls by a factor of 2 (to the n) - 1 cases. This would get very unruly if for say you had 10 or so columns to search by.
I tried to use something a little more straight forward like:
var movieQry = from m in db.Movies
where ((m.Title !=null && m.Title == searchString) ||
(m.Rating != null && m.Rating == movieRating) ||
(m.Genre != null && m.Genre == movieGenre))
select m;
but that would not return anything when you first visit the page and only works for a single filter (if I select the Genre - I get good results but not when I select Genre and Rating) and I get nothing returned when I enter a search term for Title.
Is there an easier way to accomplish? (At some point I will need to be able to search on dozens of filters for a project I will be writing... and I have other questions about how to search database for entries but for not this will get me moving in the right direction).
if you want to include the column in the criteria if it is not null then try following:
string Title = Request.QueryString["Title"];
string Rating= Request.QueryString["Rating"];
string Genre = Request.QueryString["Genre"];
var movieQry = from m in db.Movies
where ((string.IsNullOrEmpty(Title) ? true : m.Title == Title ) &&
(string.IsNullOrEmpty(Rating) ? true : m.Rating == Rating ) &&
(string.IsNullOrEmpty(Genre) ? true : m.Genre == Genre ))
select m;
Behnam was kind of on the right track. I modified the code as follows:
var movieQry2 = from m in db.Movies
where ((string.IsNullOrEmpty(searchString) ? true : m.Title.Contains(searchString)) &&
(string.IsNullOrEmpty(movieRating) ? true : m.Rating == movieRating) &&
(string.IsNullOrEmpty(movieGenre) ? true : m.Genre == movieGenre))
select m;
This works and gives good results. Sorry Behnam can't give you an accepted answer but I did tick it up as being useful. Thanks for pointing me in the right direction.
Try this:
var movieQry = db.Movies
.Where(x=> (Title == null || x.Title ==Title)
&& (Rating == null || x.Rating == Rating)
&& (Genre == null || x.Genre == Genre))
.ToList();
For other paging and sorting see MVC multiple field search

MDX - Count(.children) > 0, but .FirstChild.Name is blank

I'm trying to create a calculated member that returns a string of the value when there is only one distinct child, "Multi" when there are is more than one distinct child, and "None" when there are no children.
Specifically, I'm having trouble returning the case where there is on distinct child name. Here is my calculated measure:
WITH MEMBER [Measures].[SSN] AS
CASE
WHEN DISTINCTCOUNT([Item].[Season Code Name].Children) = 0
Then 'None'
WHEN DISTINCTCOUNT([Item].[Season Code Name].Children) = 1
Then [Item].[Season Code Name].FirstChild.Name --.Value is null
ELSE
'Multi'
END
The else returns a blank, but if I use [Item].[Season Code Name] in the crossjoin, the children show up as expected.
What am I doing wrong?
Thanks in advance for your help!
This is a classical, I do that all the times :-), missing currentMember after the hierarchy.
WITH MEMBER [Measures].[SSN] AS
CASE
WHEN DISTINCTCOUNT([Item].[Season Code Name].currentmember.Children() ) = 0
Then 'None'
WHEN DISTINCTCOUNT([Item].[Season Code Name].currentmember.Children() ) = 1
Then [Item].[Season Code Name].currentmember.FirstChild.Name --.Value is null
ELSE
'Multi'
END

Resources