有没有办法制作一个不和谐的机器人,向用户发送上述次数的消息?

Is there a way to make a discord bot that sends a user a message the mentioned number of times?

我一直在尝试用 discord.py 制作一个不和谐的机器人。我知道如何让机器人向指定用户发送消息,但我想知道,有没有办法将消息发送给定次数?如果可以,我该怎么做?

例如,如果用户键入 !dm @discorduser hello 5,机器人将向指定用户发送“hello”5 次。

到目前为止,我的代码是:

import discord
from discord.ext import commands

client = commands.Bot(command_prefix='.')


@client.event
async def on_ready():
print('Bot is ready.')


@client.command()
async def spam(ctx, member: discord.Member, *, content):
channel = await member.create_dm()
await channel.send(content)


client.run('bot token')

这是我对这个问题的回答,据我了解,您正在尝试向用户直接发送消息 x 次,而 x 可以根据用户的需求进行更改。

@client.command()

# the arguments are: member, the amount of times you want to DM, and what you want to DM them.
async def spam(ctx, member : discord.Member, amount=1, content=None):

    # this loop will keep doing the script below the amount of 'amount' times.
    for i in range(amount):
        channel = await member.create_dm()
        await channel.send(content)