'Discord.py | Change max_concurrency mid-command execution
I take multiple inputs from bots users, and I want to disable their use of commands while the inputs are being taken.
def check(m):
return m.channel == channel and ctx.message.author == m.author
@bot.command()
async def hello(ctx):
await ctx.send("How are you today?")
try:
response = await bot.wait_for('message', timeout=30, check=check) # I want to ensure users cannot execute a command during this stage of the command.
await ctx.send(f"Glad to see you're feeling {response.content}!")
except:
await ctx.send("You must be depressed! I didn't hear a word... :(")
I have noticed max_concurrency exists, and I feel it could be applicable in this situation.
Solution 1:[1]
You can decorate the command as follows:
@bot.command()
@commands.max_concurrency(1, commands.BucketType.member, wait=False)
async def hello(ctx):
This will cause the command to only permit one invocation per guild member at any given time. Reference BucketType and MaxConcurrency in the docs for detailed explanations of their implementations.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Grace |
