使用Discord.py

时间:2018-11-22 22:44:48

标签: python discord.py

import discord
from discord.ext.commands import Bot
from discord.ext import commands
import asyncio
import time
import random
from PIL import Image

Client = discord.Client()
client = commands.Bot(command_prefix = "-")`
@client.command
async def spam(ctx, arg):
    count = 0 
    await Context.send(message.channel, "Wait for it....")
    time.sleep(3)
    while count < 20:
        await ctx.send(arg)
        time.sleep(3)
        count = count + 1

该代码应提及自变量中指定的人。例如,如果有人输入了-spam @Bob,则该漫游器应该说

@Bob
@Bob 20 times

1 个答案:

答案 0 :(得分:0)

无需实例化discord.Clientcommands.BotBotClient的子类。

Bot.command是一个返回修饰符的函数,而不是返回修饰符本身的函数。您需要调用它才能用它来装饰协程:

@client.command()

您可能应该使用converter来获取您要查询的用户。

Contextctx实例的类。您应该通过ctx访问所有方法。

请勿使用time.sleep,因为它会阻塞事件循环。改为asyncio.sleep

from discord.ext.commands import Bot
from asyncio import sleep
from discord import User

client = Bot(command_prefix = "-")

@client.command()
async def spam(ctx, user: User):
    await ctx.send("Wait for it....")
    await sleep(3)
    for _ in range(20):
        await ctx.send(user.mention)
        await sleep(3)

client.run("token")