我如何拥有一个可以有计时器指令的机器人?

时间:2021-07-19 13:57:03

标签: discord.py

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

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

我该怎么做?

1 个答案:

答案 0 :(得分:1)

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