如何要求多个用户 ID 之一才能使命令在 Discord.py 上运行?
How to require one of multiple user id's for a command to work on Discord.py?
我是 Discord.py 的新手,我正在尝试为 cog 制作一个命令,允许我使用命令加载、卸载和重新加载 cog。
我已经完成了命令,但现在我试图让它只在我使用它的人或我的 alt 帐户时起作用。我可以让它为我的主要工作,但它会忽略我的 alt。我怎样才能让它同时适用于两者?
trusted = ('account1', 'account2', 'account3')
@client.command()
async def load(ctx, extension):
if ctx.author.id == trusted:
client.load_extension(f'cogs.{extension}')
await ctx.reply(f'loaded {extension}')
我能够使用 'else' 和 'if' 让它工作,尽管这只是将其他简单代码的长度加倍,而且我知道这种方式可以以某种方式工作,我只是现在确定该怎么做了。
正如我所说,该命令适用于 'account1',但它会忽略其他命令。我该如何修复它才能在其他帐户上使用?
感谢您的帮助!
问题是您没有列出正确的列表([]
),也没有检查其中的所有条目。
如果您在列表中存储诸如 ID 之类的内容,只需按原样存储它们并省略引号 ("
)。
您的新密码:
trusted = [ID1, ID2, ID3...] # Create a list of IDs
@client.command()
async def load(ctx, extension):
if ctx.author.id in trusted: # We check if the author.id is IN the list
#Do what you want to do
我是 Discord.py 的新手,我正在尝试为 cog 制作一个命令,允许我使用命令加载、卸载和重新加载 cog。
我已经完成了命令,但现在我试图让它只在我使用它的人或我的 alt 帐户时起作用。我可以让它为我的主要工作,但它会忽略我的 alt。我怎样才能让它同时适用于两者?
trusted = ('account1', 'account2', 'account3')
@client.command()
async def load(ctx, extension):
if ctx.author.id == trusted:
client.load_extension(f'cogs.{extension}')
await ctx.reply(f'loaded {extension}')
我能够使用 'else' 和 'if' 让它工作,尽管这只是将其他简单代码的长度加倍,而且我知道这种方式可以以某种方式工作,我只是现在确定该怎么做了。
正如我所说,该命令适用于 'account1',但它会忽略其他命令。我该如何修复它才能在其他帐户上使用?
感谢您的帮助!
问题是您没有列出正确的列表([]
),也没有检查其中的所有条目。
如果您在列表中存储诸如 ID 之类的内容,只需按原样存储它们并省略引号 ("
)。
您的新密码:
trusted = [ID1, ID2, ID3...] # Create a list of IDs
@client.command()
async def load(ctx, extension):
if ctx.author.id in trusted: # We check if the author.id is IN the list
#Do what you want to do