First Argument

const user = await args.pick("member").catch(() => null); With this code I tried to make the bot get the member from the first argument but looks like it only gets the member if the bot finds it on the second argument, third, etc, how can I fix it?
15 Replies
Lioness100
Lioness100•10mo ago
@_carlos123 Could you send your full code?
-Carlos👑
-Carlos👑•10mo ago
const { Command } = require("@sapphire/framework");

class BlacklistCommand extends Command {
constructor(context, options) {
super(context, {
...options,
preconditions: ["Owner"],
aliases: ["bl"],
description: "Blacklists a user from using the bot.",
detailedDescription: {
usage: "blacklist <Member>",
},
});
}

async messageRun(message, args) {
try {
const argument = await args.pick("string").catch(() => null);
const user = await args.pick("member").catch(() => null);

console.log(user);

if (!argument)
return this.container.util.createError(
"Provide a user to blacklist.",
message
);
else if (!user)
return this.container.util.createError(
"Provide a valid user to blacklist.",
message
);
else if (user.user.bot)
return this.container.util.createError(
"You cannot blacklist bots.",
message
);
else if (message.channel.id === user.user.id)
return this.container.util.createError(
"You cannot blacklist yourself.",
message
);

return message.channel.send(`blacklisted ${user}`)
} catch (error) {
this.container.util.handleError(message, error);
}
}
}

module.exports = {
BlacklistCommand,
};
const { Command } = require("@sapphire/framework");

class BlacklistCommand extends Command {
constructor(context, options) {
super(context, {
...options,
preconditions: ["Owner"],
aliases: ["bl"],
description: "Blacklists a user from using the bot.",
detailedDescription: {
usage: "blacklist <Member>",
},
});
}

async messageRun(message, args) {
try {
const argument = await args.pick("string").catch(() => null);
const user = await args.pick("member").catch(() => null);

console.log(user);

if (!argument)
return this.container.util.createError(
"Provide a user to blacklist.",
message
);
else if (!user)
return this.container.util.createError(
"Provide a valid user to blacklist.",
message
);
else if (user.user.bot)
return this.container.util.createError(
"You cannot blacklist bots.",
message
);
else if (message.channel.id === user.user.id)
return this.container.util.createError(
"You cannot blacklist yourself.",
message
);

return message.channel.send(`blacklisted ${user}`)
} catch (error) {
this.container.util.handleError(message, error);
}
}
}

module.exports = {
BlacklistCommand,
};
Lioness100
Lioness100•10mo ago
It's because the first argument is const argument = await args.pick("string").catch(() => null);
-Carlos👑
-Carlos👑•10mo ago
wdym
Lioness100
Lioness100•10mo ago
user is coming from the second argument because argument is coming from the first
-Carlos👑
-Carlos👑•10mo ago
oh is there any alternative to do what i was trying to do basically I want it to say something if the user does not provide nothing at all but also say something if the user provides something but is not a vaild member
Ararou
Ararou•10mo ago
Try something like
const user = await args.pick('user').catch(() => null);
if (!user) do stuff;

const reason = await args.rest('string').catch(() => null);
if (!reason) do stuff
const user = await args.pick('user').catch(() => null);
if (!user) do stuff;

const reason = await args.rest('string').catch(() => null);
if (!reason) do stuff
lemme show with one of the bots i coded its in slash but itd be somewhat similar with the if checks
Ararou
Ararou•10mo ago
these are all with 1 argument
No description
Ararou
Ararou•10mo ago
instead of
const argument = await args.pick("string").catch(() => null);
const user = await args.pick("member").catch(() => null);
const argument = await args.pick("string").catch(() => null);
const user = await args.pick("member").catch(() => null);
-Carlos👑
-Carlos👑•10mo ago
this didn't work, since there's no reason in the command I'm trying to make i tried this:
const argument = await args.pick("string").catch(() => null);

if (!argument)
return this.container.util.createError("Provide a user to blacklist.", message);

const user = await args.pick("member").catch(() => null);

if (!user)
return this.container.util.createError("Provide a valid user to blacklist.", message);
const argument = await args.pick("string").catch(() => null);

if (!argument)
return this.container.util.createError("Provide a user to blacklist.", message);

const user = await args.pick("member").catch(() => null);

if (!user)
return this.container.util.createError("Provide a valid user to blacklist.", message);
Lioness100
Lioness100•10mo ago
@Carlos1996 use args.finished, which tells you if the user provided anything
if (args.finished)
return this.container.util.createError("Provide a user to blacklist.", message);

const user = await args.pick("member").catch(() => null);

if (!user)
return this.container.util.createError("Provide a valid user to blacklist.", message);
if (args.finished)
return this.container.util.createError("Provide a user to blacklist.", message);

const user = await args.pick("member").catch(() => null);

if (!user)
return this.container.util.createError("Provide a valid user to blacklist.", message);
-Carlos👑
-Carlos👑•10mo ago
the .createError's now work as intented but now the bot does not detect the user at all, even if I provide it in the second, third argument etc I logged user and looks like its detecting the user from the first argument correctly, no idea why it sends the if (!user) part bump
Lioness100
Lioness100•10mo ago
Can you send your code @_carlos123
Ararou
Ararou•10mo ago
Well also
const argument = await args.pick("string").catch(() => null);

if (!argument)
return this.container.util.createError("Provide a user to blacklist.", message);
const argument = await args.pick("string").catch(() => null);

if (!argument)
return this.container.util.createError("Provide a user to blacklist.", message);
isn't needed
-Carlos👑
-Carlos👑•10mo ago
wdym i'm 100% sure I already tried this but I just tried it again rn and it worked for some reason well I changed args.pick("member") to args.pick("user") but just tested both and they work maybe my vsc was having some troubles when i tried anyways ty a lot of the help