AlexzanderFlores / WOKCommands

130 stars 61 forks source link

[Slash commands] User mention returning two different values #103

Open iamk3v opened 3 years ago

iamk3v commented 3 years ago

My args log different results of a mention when I try on pc vs mobile. Ran on pc it returns an actual guildMember Object, while on mobile it returns just a mention string.

You can see the output here: https://sourceb.in/DIfmkmsnTo

Not sure if this is intentional or not, but I would love to see it at least return the same value.

All help is much appreciated

Totto16 commented 3 years ago

I tested it and got the same result, this seems to have something todo with discords behavior, its kinda weird, but its fixable, a nice thing we have for slash Commands is the ApplicationCommandOptionType, we could try to use a correct Type for discord to know this is a user, maybe that could change that, otherwise we have to preprocess the arg into a GuildMember Object.

iamk3v commented 3 years ago

I tested it and got the same result, this seems to have something todo with discords behavior, its kinda weird, but its fixable, a nice thing we have for slash Commands is the ApplicationCommandOptionType, we could try to use a correct Type for discord to know this is a user, maybe that could change that, otherwise we have to preprocess the arg into a GuildMember Object.

Yeah i thought about the same thing by adding a options parameter to the module.exports.. (without any luck)

module.exports = {
    slash: true,
    testOnly: true,
    name: 'ban',
    description: 'Bans a user, **MUST BE A MENTION**, specify number of days of messages to delete with days argument',
    minArgs: 1,
    expectedArgs: '<user> [reason] [days]',
    guildOnly: true,
    options: [{
        type: 6,
    }],
    permissions: ["BAN_MEMBERS"],

  callback: ({})..
Is there an implemented feature in WOKCommands to specify ApplicationCommandOptions?
Totto16 commented 3 years ago

No unfortunately there isnt, but I also implemented slash commands via pull request, so for completeness I try to also add that option, and I'll test if it works that way...

Totto16 commented 3 years ago

grafik The problme is not discord, I just realised, while implementing the ApplicationCommandOptions, that we have a getMemberIfExists function, that checks, if one of the args is such a mention string, so in the Picture above you can see, that mobile and desktop discord has some different string, we only check for <@! instead of also for <!

iamk3v commented 3 years ago

grafik The problme is not discord, I just realised, while implementing the ApplicationCommandOptions, that we have a getMemberIfExists function, that checks, if one of the args is such a mention string, so in the Picture above you can see, that mobile and desktop discord has some different string, we only check for <@! instead of also for <!

Ah okay, so i assume you´ll push an update which checks for both to fix mobile mentions? Will you announce if / when the update goes live?

Totto16 commented 3 years ago

I will do that, yes, but I am not the author / a maintainer of this project, so I'll pull request it then

Totto16 commented 3 years ago

I coded everything, that you need to make that, so: you now have avaiable a options property in the commands file, you have to declare and array of objects (for one argument an object is enough) it can have these attributes: type(1-9) or the string like "user" or "USER", then you cna declare another optional choices key, you can put there a choices array of strings or ints for choices ONLY for this types, then you have the whole boolean attribute, if you dont set this to true, you get the user/role/channel object with VERY redeuced information, like this one

{
    avatar: 'f5ac82821e9f34aaf3f3732aad630030',
    bot: true,
    discriminator: '0537',
    id: '759395211713082724',
    public_flags: 0,
    username: 'Bot'
  }

this information gets send with the slash interaction type and you get it by default, however if whole is true, you get the whole user object fetched by discord.js, keep in mind, it gets it from the cache, but if not present it has to fetch it, so you have a speed disadvantage, I would suggest, to fetch it yourself if you need more information, beacuse then you can reply instantly with interaction.loading() -> fetch all data needed and then -> interaction.send(...) and your user doesn't think the bot is slow (#97 is the pull request)

iamk3v commented 3 years ago

Thank you! i assume this new array is written with something like this:?

module.exports = {
    slash: true,
    options: [{
        type: 6,
    }],
    name: "example",
    ...

Would it be possible to provide an exact example? Haven't seen an update on docs with the newly added options :)

Totto16 commented 3 years ago

Yes of course, and its not in the docs since its hasnt been approved or accepted into the main branch

 module.exports={
    name:"test",
    testOnly: true,
    guildOnly: false,
     expectedArgs: '<test> <test0> <test1> <test2> <test3> <test4> <test5> <test6> <test7> <test8>',
    options: [{
        type: 3,
        choices:["choice nr 1","Or that","Third one","Another one","5."]
    },{
        type: 4,
            choices:[1,2,3,4.01,5,6]
    },{
        type: 5,
    },{
        type:6,
    },{
        type: 7,
        whole:true
    },{
        type: 8,
    },{
        type: 9,
    }], 
    description: 'A simple test command',
    slash:"both",
    category: 'General',
    callback: async  ({message,interaction,client,args,slash}) => {
        console.log(args)
        if(!slash){
            message.channel.send("test successful");
        }else{
        interaction.loading().then(message =>{
                interaction.reply("whatever...");
            });
        }
    }
}
FeeshDev commented 3 years ago

I see embeds aren't working as well as the subcommand types, are you planning to work on those as well or will you wait on if / when it gets approved? if you even plan on doing the rest at all.

Totto16 commented 3 years ago

I plan to do the rest also, but first I wanted to have some feedback, if the implementation is ok and if everything is fine with the existinf code

FeeshDev commented 3 years ago

I plan to do the rest also, but first I wanted to have some feedback, if the implementation is ok and if everything is fine with the existinf code

I can't really say anything about the implementation, but from my experience actually using it everything is going well especially having a clear indication on if the command used is the slash version as well as having more and easier control over the integration message

Totto16 commented 3 years ago

Super if its going well, so I'll try to look at the types SUBCOMMAND and SUBCOMMAND_GROUP, the embed things isn't that complicated, in the moment you can pass embeds as {embeds:[embed]}, but thats a quick fix, something I also want to look into is the built in Permission Sytstem Discord offers for slash commands something I also urgently have to do is write a documentation 😅

FeeshDev commented 3 years ago

I'll try out the embed thing whenever I get the chance, I also wasn't aware they had built-in permissions which is great. Docs would definitely be helpful, however some of the stuff makes sense for people with experience or that have read discord slash command docs, so until approved I don't think it's a major thing, but then again I don't have much experience with this type of stuff, either way, good luck with it

Totto16 commented 3 years ago

Thanks