Can't understand why my args doesn't work in discord.js - arguments

Well, so I was trying to make code that won't send embed if args isn't defined
var member = message.mentions.members.first();
If(args[0] == member) {
//Here's my embed
} else {
channel.message.send('you need to mention someone to do it');
}
I was trying to find answers why it won't work but couldn't found anything about. Also I was trying to replace if(args[0] == member) with if(args[1] == member) or if(args[0] == message.mention.members.first()) but it didn't help. I'm new in JavaScript and don't know a lot about it so please help me.

If I think I know what your doing, This will work.
var member = message.mentions.users.first(); //Gets the pinged user.
if(!member) return message.reply("There is no user defined in this message.")//checks if a member is pinged.
//rest of code
member doesn't need to be set as a argument, This will work the same way.
I am using discord.js version 11.5.1, Hopefully this will still work for you.

Related

JavaScript Ajax - Prevent Division by Zero Function

I am building a calculator for a class using AJAX. I am having issues with my if else statement not working. It is supposed to display an alert, telling the user that they cannot divide by zero except the alert never shows. I am a beginner to Ajax, if anyone could provide guidance, it'd be greatly appreciated - I know it's probably something simple that I'm overlooking. Below is my function:
...
}
function divFunc() {
var fn = "divide";
getResult(fn);
event.preventDefault();
return;
if (frmMain.txtBxSecNum.value == 0) {
$('#alert').text("You cannot divide by zero!");
}
else { (frmMain.txtBxFirstNum.value == 0)
$('#alert').text("You cannot divide by zero!");
}
}
...
Please remove 『return;』
This statement does not work because return is added above, so the following statement is not executed

How to get Clutter.Actor via its name

I am using GJS, how do I get Clutter.Actor via its name. For example, if I wanted to get GNOME Shell's top panel, how do I get its Clutter.Actor via its name "panel"?
My research ended up somewhere along Clutter.Stage which is where Actor(s) can go be appended to, however by the way I see things, there can be multiple Stages setup so I might also have to find which Stage it is the Actor I am trying to find is at. For now I want to know how I can get an Actor via its name.
I have seen from a code; Main.layoutManager.panelBox to get the GNOME Shell's top panel, however that doesn't seem applicable to my case since it's a third party Actor I am trying to get, and the way I wish to get Actor(s) is via the name since I may be working with different third party Actor(s).
There is one way that I can get this that I know of; Main.layoutManager.panelBox.get_parent().get_children() and I can just get the specific Actor via its index, but I don't think this is the best way to approach this, considering how dynamic things are, secondly, I find this way kinda sloppy so..
I was able to get the name via Looking Glass (Alt + F2 -> lg -> picker). For now, the specific Actor I am trying to get is the DashtoDock's, just for info.
Thank you~ Hope someone can help.
Unfortunately, it seems like what you're looking for is a searchByName() function, but you'll have to implement that yourself I think. Something like (untested):
function searchByName(topActor, name) {
let children = topActor.get_children();
for (let i = 0; i < children.length; i++) {
if (child.name === name) {
return child;
} else if (child.get_n_children()) {
let result = searchByName(child, name);
if (result) {
return result;
}
}
}
return false;
};
Then call it on Main.layoutManager.uiGroup where Dash to Dock is
const Main = imports.ui.main;
let dashToDock = searchByName(Main.layoutManager.uiGroup, "dashtodockContainer");

Swift if statement not returning value

In the block of Code below, String(quakeTsunamiWarning) isn't returning with any response, and is giving the error Use of Unresolved Identifier 'quakeTsunamiWarning'
I'd like to apologise in advance if something is obviously wrong or blatantly obvious, but i'm still rather new when it comes to Programming with Swift. (Going off free tutorials I can find on Google here, as I don't have the funds to pay for a course or paid tutorial)
var quakeTsunami = 0
func newQuake() -> Void {
if quakeTsunami == 0 {
var quakeTsunamiWarning = "False"
} else if quakeTsunami == 1 {
var quakeTsunamiWarning = "True"
} else {
var quakeTsunamiWarning = "N/A"
}
println(String(quakeTsunamiWarning))
}
I've removed all the other code from the example, for sake of keeping this post relatively small, but here's a link to a gist if you want the full document. https://gist.github.com/kurisubrooks/0ba9f7547ee960657dec
Thanks in advance!
You have three separate quakeTsunamiWarning variables, each only visible inside the innermost containing {}. Move it outside the if/else structure:
var quakeTsunamiWarning: String
if quakeTsunami == 0 {
quakeTsunamiWarning = "False"
} …
And you don't need to convert it to String since it already is a String.

How do Group by a child property of a child property that may be null?

How could I go about grouping the following?
people.GroupBy(p=>p.Addresses.GetFirstOrDefault().State);
without it failing on people who don't have an Address?
can it be done in one statement?
if not, do I have to first get a Distinct() list of all the various addresses members? How? (actually -- even if a is possible -- would be great to also learn how to do b :-) )
I havn't seen it, but is there something equivalent to a GetFirstOrNew() that can be used to instantiate and return a non-null?
Thank you very much!
It can be done in one statement, yes:
// Set up whatever you need
Address dummyAddress = new Address { State = "" };
people.GroupBy(p => (p.Addresses.GetFirstOrDefault() ?? dummyAddress).State);
Alternatively, you might want to write a helper method:
public string GetState(Address address)
{
return address == null ? null : address.State;
}
Then you can use:
people.GroupBy(p => GetState(p.Addresses.GetFirstOrDefault()));

Conversion of Gdk Events in Mono

I'm trying to intercept events using Gdk.Window.AddFilter(Gdk.FilterFunc) in Mono. So far, I have been able to hook up the filter function, but now I am trying to use the events in the filter function.
This is what I have in the filter function so far:
private Gdk.FilterReturn FilterFunction(IntPtr xEvent, Gdk.Event evnt)
{
if (evnt.Type == Gdk.EventType.KeyPress)
{
Gdk.EventKey eventKey = (Gdk.EventKey)evnt; // fails here
if (eventKey.Key == this.key && eventKey.State == this.modifiers)
{
this.OnPressed(EventArgs.Empty);
}
}
return Gdk.FilterReturn.Continue;
}
How can I convert the Gdk.Event to Gdk.EventKey? I have tried casting it, but that doesn't seem to work.
Edit: Oops! The problem was that I had accidentally added a semicolon to the if statement, making it an empty statement. For some reason, the Gdk.Event does not correspond to the XEvent, so I am now pursuing a solution that uses the XEvent instead.
Why don't you try printing out the type so you can see what it really is? (it may not be EventKey)
Like:
Console.WriteLine (evnt.GetType ());
(or pause it in a debugger and examine it to see the type)

Resources