存在/活动设置命令? [英] A presence/activity set command?

查看:85
本文介绍了存在/活动设置命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我想知道是否可以编写一个命令来设置机器人的状态和活动(例如~~设置空闲状态或~~设置活动以监视人们在打字~~帮助)或

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 typing ~~help") or something like that.

不相关的问题:如何设置仅由我使用的命令?

Unrelated question: How do I set commands to be used by me only?

I尚未找到任何示例代码,我是一个初学者。

I haven't found any example code for this, and i'm a beginner.

推荐答案

您可以使用 is_owner 检查以确保您是唯一可以调用命令的人。

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

要更改机器人的状态或状态,请使用 change_presence 方法:

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")

如果您尝试为 Status ActivityType 提供无法识别的名称,则以上内容将无声地失败,您也可以尝试编写错误处理程序,以提供一些反馈。

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.

这篇关于存在/活动设置命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆