如何使命令仅在另一个命令之后可用 discord.py
How to make a command available only after another discord.py
我正在尝试用 discord.py 制作俄罗斯轮盘赌机器人
如何让“加入”和“射击”命令仅在某人使用“开始”开始游戏后才可用?
使命令仅在使用其他命令后才可用的一种方法是在该命令中创建一个全局变量并在下一个命令中调用它,如果不使用这种方式,您将收到错误消息它们的顺序正确。
示例:
@commands.command()
async def test(ctx):
global x
x = True
@commands.command()
async def test2(ctx):
print(x)
如果您在 test 之前使用 test2,您将收到以下错误:
NameError: name 'x' is not defined
你可以使用尝试除来解决这个问题
@commands.command()
async def start(ctx):
global game
game = True
@commands.command()
async def join(ctx):
try:
print(game)
except NameError:
await ctx.send('There is no game going on')
我正在尝试用 discord.py 制作俄罗斯轮盘赌机器人 如何让“加入”和“射击”命令仅在某人使用“开始”开始游戏后才可用?
使命令仅在使用其他命令后才可用的一种方法是在该命令中创建一个全局变量并在下一个命令中调用它,如果不使用这种方式,您将收到错误消息它们的顺序正确。
示例:
@commands.command()
async def test(ctx):
global x
x = True
@commands.command()
async def test2(ctx):
print(x)
如果您在 test 之前使用 test2,您将收到以下错误:
NameError: name 'x' is not defined
你可以使用尝试除来解决这个问题
@commands.command()
async def start(ctx):
global game
game = True
@commands.command()
async def join(ctx):
try:
print(game)
except NameError:
await ctx.send('There is no game going on')