discord.py - 我如何拥有一个可以有计时器指令的机器人?
问题描述
我想制作一个具有计时器命令的机器人,例如!timing 00:00:00
然后机器人说@user The alarm time you set is up!
我该怎么做?
解决方案
这会让你输入!timings 10
注意时间以秒为单位
创建机器人
import discord
import time
from discord.ext import commands
client = commands.Bot(command_prefix = '!') # Setting the command prefix
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
client.run('INSERT BOT TOKEN HERE')
接下来使用您创建的机器人,以免创建命令命令:
@client.command(help=('Set a timer or reminder'))
async def timings(ctx, *, wait:int):
user = ctx.author # Getting the user
if wait: # If a number is given
time.sleep(wait) # Waiting the number of seconds given
await ctx.send(f'Hey {user.mention} your timer is going off')
return
在@Client.event 下面添加命令
推荐阅读
- c# - 以编程方式添加的 MSMQ 队列不同于手动创建
- heroku - 如何将 docker 镜像推送到从 Docker Hub 拉取的 Heroku
- java - 列表
到地图 显示每分钟的日期元素数量 - python - 使用 Tkinter 更新实时文本框
- android - 一些自定义标记不会出现在 Android react-native-maps
- firefox - Firefox 中 MaterializeCSS 的奇怪模态行为
- php - 如何在php中复制
- excel - 使用 selenium vba 在 chrome 中自动登录
- python-3.x - 无法安装 tesserocr
- java - 如何在另一个文本字段有任何文本时禁用或隐藏一个字段,如果另一个文本框被清除,如何重新启用该字段