【问题标题】:Is there a way to make a discord bot that sends a user a message the mentioned number of times?有没有办法让一个不和谐的机器人向用户发送上述次数的消息?
【发布时间】:2021-04-18 19:15:36
【问题描述】:

我一直在尝试用 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')

【问题讨论】:

  • 到目前为止你做了什么?

标签: discord discord.py discord.py-rewrite


【解决方案1】:

这是我对这个问题的回答,据我了解,您正在尝试直接向用户发送 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)

【讨论】:

    猜你喜欢
    • 2021-03-28
    • 1970-01-01
    • 2023-04-04
    • 1970-01-01
    • 2020-11-19
    • 2020-11-12
    • 2020-05-31
    • 2022-01-08
    • 2021-04-03
    相关资源
    最近更新 更多