添加一个全局值,指示
在标题中真的很难用词。基本上,我有一个名为#start的函数,当在特定时间调用它时,它会发送一条不和谐的消息,要求我修改,直到(再次(特定时间。但当我再次谈到不和时,发现这条信息已经发送了两次。然后我尝试执行#start命令,它会发送3次相同的消息。如果我再次输入#start,它会出现4次。这是我的代码:
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"))
第四次我输入#start后,它会弹出一个错误,说:
discord.errors.NotFound: NOT FOUND (status code: 404): Unknown Message
不确定代码出了什么问题,也不知道如何阻止它的发生。请帮忙?
#start
命令是否正在运行。
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")