【发布时间】:2019-02-08 02:02:37
【问题描述】:
命令!et_as 会创建一个事件,在此事件中,每当有人发送消息时,它会在 10 秒内将计数器加一。
在 10 秒结束时,机器人会显示发送了多少条消息并开始 3 小时的冷却时间。
唯一的问题是,指示事件是否发生的变量 FeastActive 在发出第一个 !et_as 命令后不会改变。
@theclient.event
async def on_message(message):
global FeastActive
global Feast
global FeastCount
if message.author == theclient.user:
return
if FeastActive == True:
FeastCount += 1
await theclient.send_message(message.channel, ' NOM NOM NOM')
if message.content.startswith('!hello'):
msg = 'Hello {0.author.mention}'.format(message)
await theclient.send_message(message.channel, msg)
if message.content.startswith('!joke'):
r = requests.get('https://icanhazdadjoke.com', headers={"Accept":"application/json"}).text
l = json.loads(r)
await theclient.send_message(message.channel, "<@" + message.author.id + "> " + l['joke'])
if message.content.startswith('!et_as'):
if Feast == True and FeastActive == False:
Feast = False
FeastActive = True
await theclient.send_message(message.channel, "<@" + message.author.id + "> has begun a feast! Hurry, 10 seconds!")
time2.sleep(10)
FeastActive = False
await theclient.send_message(message.channel, "@everyone We have feasted on " + str(FeastCount) +" as! Next feast can start in 3 hours")
time2.sleep(10800)
Feast = True
【问题讨论】:
标签: python function global-variables discord discord.py