1 回答

TA貢獻1836條經驗 獲得超13個贊
discord.ext.commands.Command
對象具有aliases
屬性。下面是如何使用它:
@commands.command(aliases=['testcommand', 'testing'])
async def test(self, ctx):
? ? await ctx.send("This a test command")
然后,您將能夠通過編寫!test
,!testcommand
或!testing
(如果您的命令前綴是!
)來調用您的命令。
此外,如果您計劃對日志系統進行編碼,Context
則對象具有一個invoked_with
屬性,該屬性采用調用命令時使用的別名作為值。
編輯:如果你只想讓你的 cog 管理員,你可以覆蓋現有的cog_check
函數,該函數將在調用來自該 cog 的命令時觸發:
from discord.ext import commands
from discord.utils import get
class Admin(commands.Cog):
? ? def __init__(self, bot):
? ? ? ? self.bot = bot
? ? async def check_cog(self, ctx):
? ? ? ? admin = get(ctx.guild.roles, name="Admin")
? ? ? ? #False -> Won't trigger the command
? ? ? ? return admin in ctx.author.role
添加回答
舉報