首页 > 解决方案 > 我如何拥有一个可以有计时器指令的机器人?

问题描述

我想制作一个具有计时器命令的机器人,例如!timing 00:00:00

然后机器人说@user The alarm time you set is up!

我该怎么做?

标签: discord.py

解决方案


这会让你输入!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 下面添加命令


推荐阅读