discord.py bot getting cooldown time remaining of commandHow to send announcement in channel when invoking a command on cooldown (discord.py)How to get the current time in PythonPy2exe tuple index out pf range issue when creating exe filewhen install OSMnx get erroe “UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd5 in position 24: invalid continuation byte”When running bot sample code, I get this errorGetting a discord bot to mention other usersTensorFlow InvalidArgumentError/Value error occurs with small change of codeTensorflow - 'Unable to get element as bytes' error'NoneType' object has no attribute 'mention' when trying to read from MySQL with Discord.py
What do you call someone who asks many questions?
Is the Joker left-handed?
Why do I get two different answers for this counting problem?
How can I make my BBEG immortal short of making them a Lich or Vampire?
I would say: "You are another teacher", but she is a woman and I am a man
Would Slavery Reparations be considered Bills of Attainder and hence Illegal?
Is it legal for company to use my work email to pretend I still work there?
Can I ask the recruiters in my resume to put the reason why I am rejected?
Brothers & sisters
Theorems that impeded progress
Watching something be written to a file live with tail
Is it possible to run Internet Explorer on OS X El Capitan?
Has there ever been an airliner design involving reducing generator load by installing solar panels?
Memorizing the Keyboard
What's the point of deactivating Num Lock on login screens?
Why does Arabsat 6A need a Falcon Heavy to launch
What is the word for reserving something for yourself before others do?
Did Shadowfax go to Valinor?
Could gravitational lensing be used to protect a spaceship from a laser?
A reference to a well-known characterization of scattered compact spaces
What's the difference between 'rename' and 'mv'?
Neighboring nodes in the network
Is "remove commented out code" correct English?
How to take photos in burst mode, without vibration?
discord.py bot getting cooldown time remaining of command
How to send announcement in channel when invoking a command on cooldown (discord.py)How to get the current time in PythonPy2exe tuple index out pf range issue when creating exe filewhen install OSMnx get erroe “UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd5 in position 24: invalid continuation byte”When running bot sample code, I get this errorGetting a discord bot to mention other usersTensorFlow InvalidArgumentError/Value error occurs with small change of codeTensorflow - 'Unable to get element as bytes' error'NoneType' object has no attribute 'mention' when trying to read from MySQL with Discord.py
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I'm working on a python based discord bot that has the following command
@client.command(name="Mine",
description="Mine daily.",
brief="Mine daily.",
aliases=['mine', 'm'],
pass_context=True)
@commands.cooldown(1, 30, commands.BucketType.user)
async def mine(ctx, arg):
<content>
But when users hit the 30 second rate limit of the command it outputs the error to the python shell
Ignoring exception in command Mine
Traceback (most recent call last):
File "C:UsersranerAppDataLocalProgramsPythonPython36libsite-
packagesdiscordextcommandsbot.py", line 846, in process_commands
yield from command.invoke(ctx)
File "C:UsersranerAppDataLocalProgramsPythonPython36libsite-
packagesdiscordextcommandscore.py", line 367, in invoke
yield from self.prepare(ctx)
File "C:UsersranerAppDataLocalProgramsPythonPython36libsite-
packagesdiscordextcommandscore.py", line 351, in prepare
raise CommandOnCooldown(bucket, retry_after)
discord.ext.commands.errors.CommandOnCooldown: You are on cooldown. Try
again in 28.58s
What I want to do is have something that gets the remaining cooldown and puts it into something that can be said back to the user on discord e.g. 'This command is ratelimited, please try again in 28.58s'
I haven't been able to find much help for this online, and most of it is outdated or doesn't seem to work.
Thanks!
python discord discord.py
add a comment |
I'm working on a python based discord bot that has the following command
@client.command(name="Mine",
description="Mine daily.",
brief="Mine daily.",
aliases=['mine', 'm'],
pass_context=True)
@commands.cooldown(1, 30, commands.BucketType.user)
async def mine(ctx, arg):
<content>
But when users hit the 30 second rate limit of the command it outputs the error to the python shell
Ignoring exception in command Mine
Traceback (most recent call last):
File "C:UsersranerAppDataLocalProgramsPythonPython36libsite-
packagesdiscordextcommandsbot.py", line 846, in process_commands
yield from command.invoke(ctx)
File "C:UsersranerAppDataLocalProgramsPythonPython36libsite-
packagesdiscordextcommandscore.py", line 367, in invoke
yield from self.prepare(ctx)
File "C:UsersranerAppDataLocalProgramsPythonPython36libsite-
packagesdiscordextcommandscore.py", line 351, in prepare
raise CommandOnCooldown(bucket, retry_after)
discord.ext.commands.errors.CommandOnCooldown: You are on cooldown. Try
again in 28.58s
What I want to do is have something that gets the remaining cooldown and puts it into something that can be said back to the user on discord e.g. 'This command is ratelimited, please try again in 28.58s'
I haven't been able to find much help for this online, and most of it is outdated or doesn't seem to work.
Thanks!
python discord discord.py
add a comment |
I'm working on a python based discord bot that has the following command
@client.command(name="Mine",
description="Mine daily.",
brief="Mine daily.",
aliases=['mine', 'm'],
pass_context=True)
@commands.cooldown(1, 30, commands.BucketType.user)
async def mine(ctx, arg):
<content>
But when users hit the 30 second rate limit of the command it outputs the error to the python shell
Ignoring exception in command Mine
Traceback (most recent call last):
File "C:UsersranerAppDataLocalProgramsPythonPython36libsite-
packagesdiscordextcommandsbot.py", line 846, in process_commands
yield from command.invoke(ctx)
File "C:UsersranerAppDataLocalProgramsPythonPython36libsite-
packagesdiscordextcommandscore.py", line 367, in invoke
yield from self.prepare(ctx)
File "C:UsersranerAppDataLocalProgramsPythonPython36libsite-
packagesdiscordextcommandscore.py", line 351, in prepare
raise CommandOnCooldown(bucket, retry_after)
discord.ext.commands.errors.CommandOnCooldown: You are on cooldown. Try
again in 28.58s
What I want to do is have something that gets the remaining cooldown and puts it into something that can be said back to the user on discord e.g. 'This command is ratelimited, please try again in 28.58s'
I haven't been able to find much help for this online, and most of it is outdated or doesn't seem to work.
Thanks!
python discord discord.py
I'm working on a python based discord bot that has the following command
@client.command(name="Mine",
description="Mine daily.",
brief="Mine daily.",
aliases=['mine', 'm'],
pass_context=True)
@commands.cooldown(1, 30, commands.BucketType.user)
async def mine(ctx, arg):
<content>
But when users hit the 30 second rate limit of the command it outputs the error to the python shell
Ignoring exception in command Mine
Traceback (most recent call last):
File "C:UsersranerAppDataLocalProgramsPythonPython36libsite-
packagesdiscordextcommandsbot.py", line 846, in process_commands
yield from command.invoke(ctx)
File "C:UsersranerAppDataLocalProgramsPythonPython36libsite-
packagesdiscordextcommandscore.py", line 367, in invoke
yield from self.prepare(ctx)
File "C:UsersranerAppDataLocalProgramsPythonPython36libsite-
packagesdiscordextcommandscore.py", line 351, in prepare
raise CommandOnCooldown(bucket, retry_after)
discord.ext.commands.errors.CommandOnCooldown: You are on cooldown. Try
again in 28.58s
What I want to do is have something that gets the remaining cooldown and puts it into something that can be said back to the user on discord e.g. 'This command is ratelimited, please try again in 28.58s'
I haven't been able to find much help for this online, and most of it is outdated or doesn't seem to work.
Thanks!
python discord discord.py
python discord discord.py
asked Sep 12 '18 at 15:34
user10354136user10354136
82
82
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You'll need to write an error handler for your command that handles the CommandOnCooldown
error and sends the message.
@mine.error
async def mine_error(error, ctx):
if isinstance(error, commands.CommandOnCooldown):
msg = 'This command is ratelimited, please try again in :.2fs'.format(error.retry_after)
await client.send_message(ctx.message.channel, msg)
else:
raise error
Thanks for your answer! I've put this command on the same level as my other commands, but doesn't output anything in chat or in the shell, although it does remove the original error message from the shell. Am I missing something else?
– user10354136
Sep 12 '18 at 15:42
It needs to be after themine
command. Could you add aprint
in the handler to see if execution is making ti there?
– Patrick Haugh
Sep 12 '18 at 15:47
The code works, but the output number is 20 decimal places long, is there any way to shorten this?
– user10354136
Sep 12 '18 at 15:50
Sure, change""
to":.nf"
, wheren
is the number of decimal places you want. I've edited my answer to have n=2
– Patrick Haugh
Sep 12 '18 at 15:53
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52298850%2fdiscord-py-bot-getting-cooldown-time-remaining-of-command%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You'll need to write an error handler for your command that handles the CommandOnCooldown
error and sends the message.
@mine.error
async def mine_error(error, ctx):
if isinstance(error, commands.CommandOnCooldown):
msg = 'This command is ratelimited, please try again in :.2fs'.format(error.retry_after)
await client.send_message(ctx.message.channel, msg)
else:
raise error
Thanks for your answer! I've put this command on the same level as my other commands, but doesn't output anything in chat or in the shell, although it does remove the original error message from the shell. Am I missing something else?
– user10354136
Sep 12 '18 at 15:42
It needs to be after themine
command. Could you add aprint
in the handler to see if execution is making ti there?
– Patrick Haugh
Sep 12 '18 at 15:47
The code works, but the output number is 20 decimal places long, is there any way to shorten this?
– user10354136
Sep 12 '18 at 15:50
Sure, change""
to":.nf"
, wheren
is the number of decimal places you want. I've edited my answer to have n=2
– Patrick Haugh
Sep 12 '18 at 15:53
add a comment |
You'll need to write an error handler for your command that handles the CommandOnCooldown
error and sends the message.
@mine.error
async def mine_error(error, ctx):
if isinstance(error, commands.CommandOnCooldown):
msg = 'This command is ratelimited, please try again in :.2fs'.format(error.retry_after)
await client.send_message(ctx.message.channel, msg)
else:
raise error
Thanks for your answer! I've put this command on the same level as my other commands, but doesn't output anything in chat or in the shell, although it does remove the original error message from the shell. Am I missing something else?
– user10354136
Sep 12 '18 at 15:42
It needs to be after themine
command. Could you add aprint
in the handler to see if execution is making ti there?
– Patrick Haugh
Sep 12 '18 at 15:47
The code works, but the output number is 20 decimal places long, is there any way to shorten this?
– user10354136
Sep 12 '18 at 15:50
Sure, change""
to":.nf"
, wheren
is the number of decimal places you want. I've edited my answer to have n=2
– Patrick Haugh
Sep 12 '18 at 15:53
add a comment |
You'll need to write an error handler for your command that handles the CommandOnCooldown
error and sends the message.
@mine.error
async def mine_error(error, ctx):
if isinstance(error, commands.CommandOnCooldown):
msg = 'This command is ratelimited, please try again in :.2fs'.format(error.retry_after)
await client.send_message(ctx.message.channel, msg)
else:
raise error
You'll need to write an error handler for your command that handles the CommandOnCooldown
error and sends the message.
@mine.error
async def mine_error(error, ctx):
if isinstance(error, commands.CommandOnCooldown):
msg = 'This command is ratelimited, please try again in :.2fs'.format(error.retry_after)
await client.send_message(ctx.message.channel, msg)
else:
raise error
edited Feb 5 at 3:07
answered Sep 12 '18 at 15:38
Patrick HaughPatrick Haugh
30.7k92849
30.7k92849
Thanks for your answer! I've put this command on the same level as my other commands, but doesn't output anything in chat or in the shell, although it does remove the original error message from the shell. Am I missing something else?
– user10354136
Sep 12 '18 at 15:42
It needs to be after themine
command. Could you add aprint
in the handler to see if execution is making ti there?
– Patrick Haugh
Sep 12 '18 at 15:47
The code works, but the output number is 20 decimal places long, is there any way to shorten this?
– user10354136
Sep 12 '18 at 15:50
Sure, change""
to":.nf"
, wheren
is the number of decimal places you want. I've edited my answer to have n=2
– Patrick Haugh
Sep 12 '18 at 15:53
add a comment |
Thanks for your answer! I've put this command on the same level as my other commands, but doesn't output anything in chat or in the shell, although it does remove the original error message from the shell. Am I missing something else?
– user10354136
Sep 12 '18 at 15:42
It needs to be after themine
command. Could you add aprint
in the handler to see if execution is making ti there?
– Patrick Haugh
Sep 12 '18 at 15:47
The code works, but the output number is 20 decimal places long, is there any way to shorten this?
– user10354136
Sep 12 '18 at 15:50
Sure, change""
to":.nf"
, wheren
is the number of decimal places you want. I've edited my answer to have n=2
– Patrick Haugh
Sep 12 '18 at 15:53
Thanks for your answer! I've put this command on the same level as my other commands, but doesn't output anything in chat or in the shell, although it does remove the original error message from the shell. Am I missing something else?
– user10354136
Sep 12 '18 at 15:42
Thanks for your answer! I've put this command on the same level as my other commands, but doesn't output anything in chat or in the shell, although it does remove the original error message from the shell. Am I missing something else?
– user10354136
Sep 12 '18 at 15:42
It needs to be after the
mine
command. Could you add a print
in the handler to see if execution is making ti there?– Patrick Haugh
Sep 12 '18 at 15:47
It needs to be after the
mine
command. Could you add a print
in the handler to see if execution is making ti there?– Patrick Haugh
Sep 12 '18 at 15:47
The code works, but the output number is 20 decimal places long, is there any way to shorten this?
– user10354136
Sep 12 '18 at 15:50
The code works, but the output number is 20 decimal places long, is there any way to shorten this?
– user10354136
Sep 12 '18 at 15:50
Sure, change
""
to ":.nf"
, where n
is the number of decimal places you want. I've edited my answer to have n=2– Patrick Haugh
Sep 12 '18 at 15:53
Sure, change
""
to ":.nf"
, where n
is the number of decimal places you want. I've edited my answer to have n=2– Patrick Haugh
Sep 12 '18 at 15:53
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52298850%2fdiscord-py-bot-getting-cooldown-time-remaining-of-command%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown