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("~~")
def getEnum(enum):
def getter(arg):
return enum[arg]
return getter
@bot.group(invoke_without_command=True)
@is_owner()
async def set(ctx):
await ctx.send("You must provide a subcommand.")
@set.command()
async def presence(ctx, status: getEnum(Status)):
await bot.change_presence(status=status)
@set.command(invoke_without_command=True)
async def activity(ctx, type: getEnum(ActivityType), *, description):
await bot.change_presence(activity=Activity(type=type, name=description))
@set.error
async def set_error(ctx, error):
if isinstance(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?"