#Hide Commands

1 messages · Page 1 of 1 (latest)

storm basin
#

Possible to hide certain commands to specific channels/roles, e.g if user doesn't have the required role and uses /command it wont show at all?

There are certain commands i would like to block the general public from seeing options for!

gaunt pumiceBOT
#

Hey! Once your issue is solved, press the button below to close this thread!

wispy niche
#

the most you can do is set default_member_permissions

#

if you want developer commands, its best to sync those only to one guild that you own or just use prefixed commands

#

otherwise, you can tell owners/admins of servers to enable whatever commands they want normal people to use only in certain channels or whatever

tulip verge
#

@wispy niche On the topic of this, is it possible to limit commands to certain channels? so that they can only be used in that channel?

#

or does it require my own decorator/Check to be made?

#

Also When you use a slash command it shows you the options that you used meaning other people can see those options, anyway to also turn off?

glacial pollen
tulip verge
tulip verge
# glacial pollen as workaround you can do ctx.channel.send instead

use command > send status message > sends request to api > update status message based on request response.

thats the flow of my command if that helps, the origin message is being updated succesfully based on the status, however even when successful it says application didnt respond

glacial pollen
#

or else discord thinks the bot hasn't responded

tulip verge
#

and theres no way around that? I'd preferably just want to update the original message

glacial pollen
#

you can send a private message only visible to the person that used the command

glacial pollen
#

ctx.send so discord knows the bot acknowledged the interaction, optionally with the ephemeral=True parameter, and then ctx.channel.send your message

#

I usually just put a checkmark in the ephemeral message

glacial pollen
#

ctx.send('✔️ ', ephemeral=True)

#

ctx.channel.send('The usual response')

storm basin
#

thanks, and you cant use the ephemeral arg in channel.send?

glacial pollen
#

why would you need it?

#

and no because it's not responding to an interaction context (ctx)

storm basin
#

thanks alot!

glacial pollen
#

don't forget the awaits

#

like I did just now

#

I can show you an example if you need it @tulip verge

tulip verge
tulip verge
#

now that i think of it though, maybe thats a permission problem?

glacial pollen
#

*component callback, not command

#

this is the initial value for the message variable

#

which is getting edited by the shown component callback

tulip verge
#

this is what im doing:

`embed = interactions.Embed(title=f'Doing Said Task', color=interactions.MaterialColors.BLUE)
progress_message = await ctx.send(embed=embed, ephemeral=True)

data = {'some_data': some_data}

try:
    async with aiohttp.ClientSession() as session:
        response = await session.delete(f'route', headers=headers, json=data)
        
        if not response.ok:
            data = await response.json()
            embed_title = 'Failed to do task
            fields = [
                {'name': 'task1', 'value': data['task1']},
                {'name': 'Reason', 'value': reason},
            ]
            success = False
            embed = create_embed_with_fields(embed_title, fields, success)

            await progress_message.edit(embed=embed)
            `
tulip verge
#

and the bot does have admin perms

wispy niche
#

its not a permission problem

#

use ctx.edit(message, ...) whenever youre editing interaction stuff

tulip verge
wispy niche
#

that... should not be happening

#

youre passing in progress_message, yeah?

tulip verge
#

yeah

#

and i can see from the attempted request

#

the message its looking for is correct

#

the ID matches

wispy niche
#

WAIT

#

oops i meant it in lowercase

#

...what type of ctx is this?

tulip verge
#

slash Context

wispy niche
#

gotcha

tulip verge
#

wait

#

nvm

#

i forgot slash content as the ctx

#

still doesnt work when i add it though

wispy niche
#

it works fine for me with a live test rn

tulip verge
#

i can send the full command if you want

wispy niche
#

i think full command code would be best

#

ive tried a number of things but i cant replicate it

tulip verge
#

sure

#

1 sec

#

`@check(interactions.has_any_role(manager_role_id, owner_role_id)) # type: ignore
@slash_command(name="commandname", description="do command", dm_permission=False, options=[interactions.SlashCommandOption(name='command_option', description='a', type=interactions.OptionType.INTEGER, required=True)])
async def commandname(ctx: SlashContext, arg_name: int):

embed = interactions.Embed(title=f'doing task', color=interactions.MaterialColors.BLUE)
progress_message = await ctx.send(embed=embed, ephemeral=True)
    
data = {'ping_id': ping_id}

try:
    async with aiohttp.ClientSession() as session:
        response = await session.delete(f'route', headers=headers, json=data)
        
        if not response.ok:
            data = await response.json()
            embed_title = 'Failed to do task'
            fields = [
                {'name': 'Ping ID', 'value': data['ping_id']},
                {'name': 'Reason', 'value': data['reason']},
            ]
            success = False
            embed = create_embed_with_fields(embed_title, fields, success)
            if progress_message: 
                await progress_message.edit(embed=embed)
         
        elif response.ok:
            data = await response.json()
            embed_title = 'task done'
            fields = [
                {'name': 'Ping ID', 'value': data['ping_id']},
            ]
            success = True
            embed = create_embed_with_fields(embed_title, fields, success)
      
            await ctx.edit(progress_message, embed=embed)
        
except aiohttp.ClientError as error:
    logging.error(f"An error occurred: {str(error)}")
    await progress_message.edit(content="HTTP error occurred: An error occurred")

except Exception as error: 
    logging.error(f"An error occurred: {str(error)}")`
#

@wispy niche

wispy niche
#

this is sus

tulip verge
#

await ctx.edit(progress_message, embed=embed) and progress_message.edit both dont work

tulip verge
#

I mean that never got executed in the times ive tested it

wispy niche
#

slimed it down to this and it worked

#

theres a number of things wack with your current declaration of the command that are technically unrelated but still there

#

very importantly the difference in slash option and function parameter in yours should cause issues

#

but im guessing it doesnt, somehow?

tulip verge
#

i removed the whole try block and attempted to just send a message then edit it, same error, hence why i think its something to do with perms, but my bot has admin perms so im not sure

tulip verge
#

and no they dont cause issues for me, ive been using this format the past 5-6 commands

#

only this one which i want to be shown to user only, has caused an issue

wispy niche
#

you should be immediately be hit with an error like this due to the mismatch

tulip verge
wispy niche
#

right

tulip verge
#

the one i sent you is my function with diff variables and names

#

but yeah like i said i changed it to literally just send a message then edit it, and it doesnt work, but if i didnt have perms to edit the messages my other commands wouldnt work either, which they do

wispy niche
#

i legitimately cannot replicate this
my only theory is that your request is taking way too long

#

but that would have to be over 15 minutes long

tulip verge
#

and it came back the same

wispy niche
#

which is weird, because this works flawlessly for me, and permissions dont affect it

tulip verge
#

im stumped lol

wispy niche
#

i'll remove perms from the bot for the lolz i suppose

#

still works

tulip verge
#

feel like pulling my hair out

wispy niche
#

this suggests somethings wrong with your setup, and im not sure what

tulip verge
#

oh

#

hold on

#

when i use content for the edit

#

it works

#

but not embed

wispy niche
#

i mean, im using embed in my example

tulip verge
#

hmm

#

your right

#

something is going wrong in my setup

#

i tried embed and now it works

#

but i dont understand then, because the response is returning okay, and within an appropriate time

#

and the error being logged is suggesting the message doesnt exist, 404

wispy niche
#

frankly whatevers going on i blame discord or something

tulip verge
#

could be my embed is bad

#

if i remove the edit lines in the code (still doing the request), everything works.

#

and progress message has the same message ID inside and outside the try block

#

if i change await progress_message.edit(embed=embed) to ctx.send('whatever)

#

it works

#

but editing just doesnt

wispy niche
#

well i can tell you you'll need to do ctx.edit(message) or message.edit(ctx=ctx) for it to work in the first place even in normal conditions

#

(they do the same thing)

tulip verge
#

well

#

that works

#

so thank you veyr veyr much ily

#

however, how come progress_message.edit worked everywhere else but not with this command?

wispy niche
#

ephemeral messages arent normal messages, as you may assume

tulip verge
#

very strange indeed, but thank you nonetheless

wispy niche
#

they literally do not exist outside of the interaction - they dont appear to the channel at all

#

...and message.edit edits through the channel endpoint

#

ctx.edit (or passing in ctx) uses the interaction edit endpoint instead, and as said earlier, the message does exist within the interaction

#

for non-ephemeral messages, they also appear in the channel, so message.edit works (though has issues with some channels due to wacky slash permission stuff - ctx.edit works better then)

tulip verge
#

makes sense

wispy niche
# wispy niche for non-ephemeral messages, they also appear in the channel, so `message.edit` w...

(for anyone else curious: slash commands can run in channels the bot cant see. sending in that case is fine as that totally just interactions, but editing your own message using the channel endpoint means you run into a scenerio where you cant view the channel, so you have no message history, meaning you cant read the message to be edited in the first place. meanwhile the interaction path sidesteps all of that as interactions always can see and edit the messages it sends)

#

anyways, gonna close this unless theres anything else