#bot.change_prescence() doesn't work but gives no error?

1 messages · Page 1 of 1 (latest)

agile sable
#

My code:

@bot.slash_command(guild_ids=[1002963156273999884])
async def admin(self, inter):
    pass


@admin.sub_command()
async def status(self, inter, status: bot.status_options):
    bot = self.bot
    print(status)
    async with aiofiles.open("config.json", "r") as f:
        data = json.loads(await f.read())
    activity = disnake.Game(name=data["activity"])
    data["status"] = status
    async with aiofiles.open("config.json", "w") as f:
        await f.write(json.dumps(data, indent=4))
    print(activity)
    await bot.change_presence(status=status, activity=activity)
    await inter.response.send_message(f"{bot.emoji_check} Status set to {status}")
    print(f"Status set to {status} by {inter.author.name} ({inter.author.id})")

Print statements are me trying to debug. No error occurs and this is printed in the console correctly:

dnd
with code :)
Status set to dnd by EvilPanda (554343055029698571)
#

Oh and bot.status_options is commands.option_enum({"Online": disnake.Status.online, "Idle": disnake.Status.idle, "Do Not Disturb": disnake.Status.dnd, "Invisible": disnake.Status.invisible})

#

which seems to work

lethal raptor
#

Yeah was just about to say 😅

agile sable
lethal raptor
#

Docs mention that discord ignores somethings with presense. You might want to try using one of the others.

silent cargoBOT
#

class disnake.ActivityType```
Specifies the type of [`Activity`](https://docs.disnake.dev/page/api.html#disnake.Activity "disnake.Activity"). This is used to check how to interpret the activity itself.
agile sable
#

this is the example used in the docs:

game = disnake.Game("with the API")
await client.change_presence(status=disnake.Status.idle, activity=game)
#

i think what I'm doing is basically that

#

but with the status chosen by an enum

limpid grotto
#

Can you setup logging please?

#

might be an issue with Discord Gateway

wanton sand
#

game=disnake.Game(name="Disnake Rules???")
await self.bot.change_presence(status=disnake.Status.online, activity=game)

#

@agile sable

#

and intents.presences = True

#

also is even ```py
async with aiofiles.open("config.json", "r") as f:
data = json.loads(await f.read())
print(data) #will this print data????

#

just this looks weird af!
json.loads(await f.read())

#

looks fugly af

#

cant be real

agile sable
#

i think reaching data outside works, and surely it would save memory usage by not have both the file and data stored?

#

correct me if im wrong I have no idea how this stuff actually wokrs

wanton sand
#

u can try print data atleast

#

see if u even get a that string

#
game=disnake.Game(name="Disnake Rules???")
await self.bot.change_presence(status=disnake.Status.online, activity=game)
``` this is a working code
#

make sure u got this too intents.presences = True

agile sable
wanton sand
#

^^,

#

Well now u got something to check

#

i can post my whole status script

#
    @tasks.loop(seconds=15)
    async def service(self):
        await asyncio.sleep(15)
        streamer = await db_livestreams.Get_Streamers_Online_Count()
        offline = await db_livestreams.Get_Streamers_Offline_Count()
        top = await db_livestreams.Get_Streamers_Top()
        count_offline = 0

        #game=discord.Game(name="No streamers live.")
        if offline:
            count_offline = offline[0]["COUNT(ChannelId)"]

        if top:
            top_stats = top[0]["Name"]
            top_stats_viewers = top[0]["CurrentViewers"]


        if streamer:
            #print("We got streamers!!!!!!!!!!!!!!!!!!!!!!!!")
            #print(streamer[0]["COUNT(ChannelId)"])
            count = streamer[0]["COUNT(ChannelId)"]
            #print(count)
            if int(streamer[0]["COUNT(ChannelId)"]) == 0:
                game=disnake.Game(name="No streamers live.")
                await self.bot.change_presence(status=disnake.Status.idle, activity=game)
            else:
                string_to_show = "%s / %s Livestreaming." % (count, count_offline)
                game=disnake.Game(name=string_to_show)
                await self.bot.change_presence(status=disnake.Status.online, activity=game)
                await asyncio.sleep(15)
                string_to_show = "🔴 %s" % (top_stats)
                game=disnake.Game(name=string_to_show)
                await self.bot.change_presence(status=disnake.Status.online, activity=game)
        else:
            game=disnake.Game(name="No streamers live.")
            await self.bot.change_presence(status=disnake.Status.idle, activity=game)
``` just for ideas
agile sable
#

disnake.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: admin() missing 1 required positional argument: 'inter'

limpid grotto
#

presences intent is not required tho

agile sable
#

oh ye bc surely changing ur own presence wouldnt need that

limpid grotto
#

yeah

wanton sand
#

is that to read others?

limpid grotto
#

Yes

wanton sand
#

ight

agile sable
#

the command is in the main file so I just got rid of self in both the main slash command and sub command

limpid grotto
#

would be nice to create a Config class and use that

wanton sand
#

config file and read with main?

#

or a class ye

#

or u will open it alot of times

agile sable
#

oh yeah that would make more sense

wanton sand
#

and u can put a !reloadcfg command to re-read it

#

if make changes

#

no need restart bot

agile sable
#

normally the config is only opened once at the start, but i added this bc i want the status to always be correct in config so when I change either status or presence it will have the correct other one

wanton sand
#

or just make class in a cog and relaod cog

agile sable
wanton sand
#

takes CPU and memory

#

if u have open file on many places

agile sable
wanton sand
#

isntead of 1

#

not much cpu but memory

#

precense can take some time too?

#

to show

#

atleast few seconds

agile sable
#

it still hasnt changed

wanton sand
#

show ur new code

agile sable
#

one thing I am wondering is is this allowed?

#

commands.option_enum({"Online": disnake.Status.online, "Idle": disnake.Status.idle, "Do Not Disturb": disnake.Status.dnd, "Invisible": disnake.Status.invisible})

limpid grotto
agile sable
#

to put disnake.Status.online in the enum

agile sable
wanton sand
#

would't it be opposite?

#

{disnake.Status.online:"Online", }

#

etc

agile sable
#

I want it to show Online in the slash command options but thats what it gives to the change_presence

#

this is the docs example code so I think its right:

Animal = commands.option_enum({"Dog": "dog", "Cat": "cat", "Penguin": "penguin"})

@bot.slash_command()
async def blep(inter: disnake.ApplicationCommandInteraction, animal: Animal):
    await inter.response.send_message(animal)
wanton sand
#

ah

#

then ur correct

limpid grotto
#

I tried doing what you did and it gives me an error

#

are you sure you're doing it correct

wanton sand
#

what was the error

agile sable
wanton sand
#

I want the error 😛 cause it will explain

limpid grotto
#

TypeError: <Status.online: 'online'> is not a valid parameter annotation

wanton sand
#

:S

#

weird

#

await self.bot.change_presence(status=disnake.Status.idle, activity=game)
await self.bot.change_presence(status=disnake.Status.online, activity=game)

#

workds for me

agile sable
#

thats when I run the slash command

wanton sand
#

i dont think u should post

#

"aW50ZXJhY3Rpb246MTA1MDg0NzY1MjIyMjM0MTE3MTpBWEpLM0Q3S1BWTm1BU2tNd3VhTjRNVVdtY2FyR0ZFc1RvTFZPeXZBczNUcEVwRFA3Y3EzR2JsNTU4V0MxMmZjRWpya0VtYTdUU2RwUEMwNmY0eHRNZ09neFdDVWlaVnhzTW5KTkVDN0I3ZjRMNnFuU2ZQY3hzSEtPMWIyYWozWQ"

agile sable
#

oh is that a session id?

wanton sand
#

aint that like ur webhook key

agile sable
#

i dont think its my bot token

wanton sand
#

not bot but webhok?

agile sable
#

oh oops

#

does that change when I restart?

wanton sand
#

u make a new webhok

#

let @limpid grotto

#

confirm

#

hvnt coded disnake in long time

limpid grotto
#

it's fine

#

also I gtg, gonna watch Argentina

wanton sand
#

u from argentina?

#

messi is in trouble for moving mexican shirt with his feets 😛

agile sable
#

hmmm this is the line in the log about requesting a change of status: DEBUG:disnake.gateway:Sending "{"op":3,"d":{"status":"dnd","activities":[{"type":0,"name":"with code :)","timestamps":{},"assets":{}}],"since":0,"afk":false}}" to change status

#

but there doesnt seem to be any line which suggests it worked

limpid grotto
wanton sand
agile sable
#

I don't think I'm trying to use webhooks anywhere it's just part of the disnake code?

#

idk

limpid grotto
#

This works for me

#

class Opts(Enum):
    Online = disnake.Status.online.value
    Idle = disnake.Status.idle.value
    DND = disnake.Status.dnd.value
    Invisible = disnake.Status.invisible.value

@bot.slash_command()
async def status(inter: disnake.ApplicationCommandInteraction, status: Opts):
    await bot.change_presence(status=disnake.Status(status))
    await inter.response.send_message("Done")
#

well cya

agile sable
#

thanks ill see if I can use this

#

tyvm it is now working so I'm not entirely sure what fixed it but it works anyway

#

support here is very good