discord.py message getting sent multiple times, increases by 1 each time
up vote
1
down vote
favorite
Really hard to word in a title. Basically I have a function called #start, which when called at a specific time will send a message on discord asking me to revise until (again) a specific time. But when I go back on discord, it turns out the message has been sent twice. So then I try doing the #start command and it sends the same message 3 times. If I type in #start again, it comes up 4 times. This is my code:
if hour == 14:
await bot.send_message(message.channel, "<@258621320898543616> Why don't you try some science revision now?")
science = random.choice(sciences)
asyncio.sleep(0.5)
await bot.send_message(message.channel, "<@258621320898543616> lemme see, how about " +science+"? Look over some of that")
asyncio.sleep(1)
await bot.send_message(message.channel, "you can take a break at 3:00")
while hour >= 14 and hour < 15:
msg = await bot.wait_for_message(timeout=3, author=message.author)
if msg:
await bot.delete_message(msg)
hour = int(time.strftime("%H"))
After the 4th time i type in #start it throws up an error saying:
discord.errors.NotFound: NOT FOUND (status code: 404): Unknown Message
Not sure what's wrong with the code or how I can stop it from happening. Help please?
python bots discord discord.py
add a comment |
up vote
1
down vote
favorite
Really hard to word in a title. Basically I have a function called #start, which when called at a specific time will send a message on discord asking me to revise until (again) a specific time. But when I go back on discord, it turns out the message has been sent twice. So then I try doing the #start command and it sends the same message 3 times. If I type in #start again, it comes up 4 times. This is my code:
if hour == 14:
await bot.send_message(message.channel, "<@258621320898543616> Why don't you try some science revision now?")
science = random.choice(sciences)
asyncio.sleep(0.5)
await bot.send_message(message.channel, "<@258621320898543616> lemme see, how about " +science+"? Look over some of that")
asyncio.sleep(1)
await bot.send_message(message.channel, "you can take a break at 3:00")
while hour >= 14 and hour < 15:
msg = await bot.wait_for_message(timeout=3, author=message.author)
if msg:
await bot.delete_message(msg)
hour = int(time.strftime("%H"))
After the 4th time i type in #start it throws up an error saying:
discord.errors.NotFound: NOT FOUND (status code: 404): Unknown Message
Not sure what's wrong with the code or how I can stop it from happening. Help please?
python bots discord discord.py
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
Really hard to word in a title. Basically I have a function called #start, which when called at a specific time will send a message on discord asking me to revise until (again) a specific time. But when I go back on discord, it turns out the message has been sent twice. So then I try doing the #start command and it sends the same message 3 times. If I type in #start again, it comes up 4 times. This is my code:
if hour == 14:
await bot.send_message(message.channel, "<@258621320898543616> Why don't you try some science revision now?")
science = random.choice(sciences)
asyncio.sleep(0.5)
await bot.send_message(message.channel, "<@258621320898543616> lemme see, how about " +science+"? Look over some of that")
asyncio.sleep(1)
await bot.send_message(message.channel, "you can take a break at 3:00")
while hour >= 14 and hour < 15:
msg = await bot.wait_for_message(timeout=3, author=message.author)
if msg:
await bot.delete_message(msg)
hour = int(time.strftime("%H"))
After the 4th time i type in #start it throws up an error saying:
discord.errors.NotFound: NOT FOUND (status code: 404): Unknown Message
Not sure what's wrong with the code or how I can stop it from happening. Help please?
python bots discord discord.py
Really hard to word in a title. Basically I have a function called #start, which when called at a specific time will send a message on discord asking me to revise until (again) a specific time. But when I go back on discord, it turns out the message has been sent twice. So then I try doing the #start command and it sends the same message 3 times. If I type in #start again, it comes up 4 times. This is my code:
if hour == 14:
await bot.send_message(message.channel, "<@258621320898543616> Why don't you try some science revision now?")
science = random.choice(sciences)
asyncio.sleep(0.5)
await bot.send_message(message.channel, "<@258621320898543616> lemme see, how about " +science+"? Look over some of that")
asyncio.sleep(1)
await bot.send_message(message.channel, "you can take a break at 3:00")
while hour >= 14 and hour < 15:
msg = await bot.wait_for_message(timeout=3, author=message.author)
if msg:
await bot.delete_message(msg)
hour = int(time.strftime("%H"))
After the 4th time i type in #start it throws up an error saying:
discord.errors.NotFound: NOT FOUND (status code: 404): Unknown Message
Not sure what's wrong with the code or how I can stop it from happening. Help please?
python bots discord discord.py
python bots discord discord.py
asked Nov 11 at 14:30
brandone
255
255
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
Add a global value indicating whether or not the #start
command is running.
from discord.ext.commands import Bot
bot = Bot(command_prefix='#')
start_running = False
@bot.event
async def on_message(message):
global start_running
if message.content.startswith('#start'):
if not start_running:
start_running = True
# do stuff
start_running = False
bot.run("token")
problem is that the whole code i typed (along with many other while loops and if statements for different times throughout the day) is inside a singleif message.content.startswith('#start'):
statement. And this if statement is inside aasync def on_message()
coroutine. I did this so If i were to type in #start at anytime throughout the day, it would reply with whatever task is set for that time
– brandone
Nov 11 at 16:05
soo it's not really a command per se.
– brandone
Nov 11 at 16:07
and doing it that way prevents me from using anything to do withmessage
– brandone
Nov 11 at 16:22
is there any way to make it so thewait_for_message()
uses a user ID to determine if a message is taken?
– brandone
Nov 11 at 16:25
@brandone You can easily do this withon_message
, see my example above. If the command is just supposed to respond with the task for that time, why is there a loop at all?
– Patrick Haugh
Nov 11 at 16:29
|
show 2 more comments
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
Add a global value indicating whether or not the #start
command is running.
from discord.ext.commands import Bot
bot = Bot(command_prefix='#')
start_running = False
@bot.event
async def on_message(message):
global start_running
if message.content.startswith('#start'):
if not start_running:
start_running = True
# do stuff
start_running = False
bot.run("token")
problem is that the whole code i typed (along with many other while loops and if statements for different times throughout the day) is inside a singleif message.content.startswith('#start'):
statement. And this if statement is inside aasync def on_message()
coroutine. I did this so If i were to type in #start at anytime throughout the day, it would reply with whatever task is set for that time
– brandone
Nov 11 at 16:05
soo it's not really a command per se.
– brandone
Nov 11 at 16:07
and doing it that way prevents me from using anything to do withmessage
– brandone
Nov 11 at 16:22
is there any way to make it so thewait_for_message()
uses a user ID to determine if a message is taken?
– brandone
Nov 11 at 16:25
@brandone You can easily do this withon_message
, see my example above. If the command is just supposed to respond with the task for that time, why is there a loop at all?
– Patrick Haugh
Nov 11 at 16:29
|
show 2 more comments
up vote
1
down vote
Add a global value indicating whether or not the #start
command is running.
from discord.ext.commands import Bot
bot = Bot(command_prefix='#')
start_running = False
@bot.event
async def on_message(message):
global start_running
if message.content.startswith('#start'):
if not start_running:
start_running = True
# do stuff
start_running = False
bot.run("token")
problem is that the whole code i typed (along with many other while loops and if statements for different times throughout the day) is inside a singleif message.content.startswith('#start'):
statement. And this if statement is inside aasync def on_message()
coroutine. I did this so If i were to type in #start at anytime throughout the day, it would reply with whatever task is set for that time
– brandone
Nov 11 at 16:05
soo it's not really a command per se.
– brandone
Nov 11 at 16:07
and doing it that way prevents me from using anything to do withmessage
– brandone
Nov 11 at 16:22
is there any way to make it so thewait_for_message()
uses a user ID to determine if a message is taken?
– brandone
Nov 11 at 16:25
@brandone You can easily do this withon_message
, see my example above. If the command is just supposed to respond with the task for that time, why is there a loop at all?
– Patrick Haugh
Nov 11 at 16:29
|
show 2 more comments
up vote
1
down vote
up vote
1
down vote
Add a global value indicating whether or not the #start
command is running.
from discord.ext.commands import Bot
bot = Bot(command_prefix='#')
start_running = False
@bot.event
async def on_message(message):
global start_running
if message.content.startswith('#start'):
if not start_running:
start_running = True
# do stuff
start_running = False
bot.run("token")
Add a global value indicating whether or not the #start
command is running.
from discord.ext.commands import Bot
bot = Bot(command_prefix='#')
start_running = False
@bot.event
async def on_message(message):
global start_running
if message.content.startswith('#start'):
if not start_running:
start_running = True
# do stuff
start_running = False
bot.run("token")
edited Nov 11 at 16:27
answered Nov 11 at 15:29
Patrick Haugh
26.3k82546
26.3k82546
problem is that the whole code i typed (along with many other while loops and if statements for different times throughout the day) is inside a singleif message.content.startswith('#start'):
statement. And this if statement is inside aasync def on_message()
coroutine. I did this so If i were to type in #start at anytime throughout the day, it would reply with whatever task is set for that time
– brandone
Nov 11 at 16:05
soo it's not really a command per se.
– brandone
Nov 11 at 16:07
and doing it that way prevents me from using anything to do withmessage
– brandone
Nov 11 at 16:22
is there any way to make it so thewait_for_message()
uses a user ID to determine if a message is taken?
– brandone
Nov 11 at 16:25
@brandone You can easily do this withon_message
, see my example above. If the command is just supposed to respond with the task for that time, why is there a loop at all?
– Patrick Haugh
Nov 11 at 16:29
|
show 2 more comments
problem is that the whole code i typed (along with many other while loops and if statements for different times throughout the day) is inside a singleif message.content.startswith('#start'):
statement. And this if statement is inside aasync def on_message()
coroutine. I did this so If i were to type in #start at anytime throughout the day, it would reply with whatever task is set for that time
– brandone
Nov 11 at 16:05
soo it's not really a command per se.
– brandone
Nov 11 at 16:07
and doing it that way prevents me from using anything to do withmessage
– brandone
Nov 11 at 16:22
is there any way to make it so thewait_for_message()
uses a user ID to determine if a message is taken?
– brandone
Nov 11 at 16:25
@brandone You can easily do this withon_message
, see my example above. If the command is just supposed to respond with the task for that time, why is there a loop at all?
– Patrick Haugh
Nov 11 at 16:29
problem is that the whole code i typed (along with many other while loops and if statements for different times throughout the day) is inside a single
if message.content.startswith('#start'):
statement. And this if statement is inside a async def on_message()
coroutine. I did this so If i were to type in #start at anytime throughout the day, it would reply with whatever task is set for that time– brandone
Nov 11 at 16:05
problem is that the whole code i typed (along with many other while loops and if statements for different times throughout the day) is inside a single
if message.content.startswith('#start'):
statement. And this if statement is inside a async def on_message()
coroutine. I did this so If i were to type in #start at anytime throughout the day, it would reply with whatever task is set for that time– brandone
Nov 11 at 16:05
soo it's not really a command per se.
– brandone
Nov 11 at 16:07
soo it's not really a command per se.
– brandone
Nov 11 at 16:07
and doing it that way prevents me from using anything to do with
message
– brandone
Nov 11 at 16:22
and doing it that way prevents me from using anything to do with
message
– brandone
Nov 11 at 16:22
is there any way to make it so the
wait_for_message()
uses a user ID to determine if a message is taken?– brandone
Nov 11 at 16:25
is there any way to make it so the
wait_for_message()
uses a user ID to determine if a message is taken?– brandone
Nov 11 at 16:25
@brandone You can easily do this with
on_message
, see my example above. If the command is just supposed to respond with the task for that time, why is there a loop at all?– Patrick Haugh
Nov 11 at 16:29
@brandone You can easily do this with
on_message
, see my example above. If the command is just supposed to respond with the task for that time, why is there a loop at all?– Patrick Haugh
Nov 11 at 16:29
|
show 2 more comments
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f53249712%2fdiscord-py-message-getting-sent-multiple-times-increases-by-1-each-time%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