Skip to content Skip to sidebar Skip to footer

A Presence/activity Set Command?

So, I was wondering if there could be a command I could write that allows me to set the bots presence and activity (ex. ~~set presence idle or ~~set activity watching 'people typin

Solution 1:

You can use the is_owner check to ensure that you are the only person who can invoke a command.

To change the presence or status of the bot, use the change_presence method:

from discord.ext.commands import Bot, is_owner
from discord import Status, Activity, ActivityType

bot = Bot("~~")

defgetEnum(enum):
    defgetter(arg):
        return enum[arg]
    return getter

@bot.group(invoke_without_command=True)@is_owner()asyncdefset(ctx):
    await ctx.send("You must provide a subcommand.")

@set.command()asyncdefpresence(ctx, status: getEnum(Status)):
    await bot.change_presence(status=status)

@set.command(invoke_without_command=True)asyncdefactivity(ctx, type: getEnum(ActivityType), *, description):
    await bot.change_presence(activity=Activity(type=type, name=description))

@set.errorasyncdefset_error(ctx, error):
    ifisinstance(error, BadArgument):
        await ctx.send(error.message)
        await ctx.send(error.args)

bot.run("token")

The above will fail silently if you try to provide an unrecognized name to Status or ActivityType, you could also try writing an error handler to provide some feedback.

Post a Comment for "A Presence/activity Set Command?"