【问题标题】:How to make a spam command in discord.py如何在 discord.py 中创建垃圾邮件命令
【发布时间】:2021-05-11 12:28:17
【问题描述】:

我今天刚开始学py,想做一个使用args来选择的垃圾邮件命令

  1. 消息发送多少次
  2. 我想发送的垃圾邮件是什么

我尝试过使用其他代码并将它们弯曲到我需要的地方,但现在我卡住了:

import os
import discord

client = discord.Client()

@client.event
async def on_ready():
 print(f'Connected to Discord!')

client.run('TOKEN HERE', bot=False)

bot = commands.Bot(command_prefix='.')
@bot.command(name='spam', help='Spams the input message for x number of times')
 async def spam(ctx, amount, message):

所以我的想法是:.spam [amount of times] [message to spam]

谢谢:)

(这是一个自我机器人,但只是为了和朋友和东西混在一起,我完全意识到他们的后果,但这只是为了好玩)

【问题讨论】:

    标签: python discord bots discord.py


    【解决方案1】:
        @bot.command()
    async def spam(ctx, channel : discord.TextChannel = None):
      await ctx.message.delete()
      if channel == None:
        channel = ctx.message.channel
      while True:
        await channel.send(random.choice(messages))
    

    【讨论】:

    • 你能解释一下这是如何回答这个问题的吗?
    【解决方案2】:

    很简单:

    from discord.ext import commands
    
    bot = commands.Bot(command_prefix='.')
    
    @bot.command(name='spam', help='Spams the input message for x number of times')
    async def spam(ctx, amount:int, *, message):
        for i in range(amount): # Do the next thing amount times
            await ctx.send(message) # Sends message where command was called
    
    bot.run('TOKEN HERE')
    

    这定义了一个带有两个参数的命令:整数的数量和您要发送的消息。 *, 使命令的其余部分放入消息中,否则它将在空白处停止。

    示例用法:.spam 2 Hello 发送 Hello 两次。

    您可能会在过度执行此命令时遇到Rate Limits,因此请小心。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-07-14
    • 2021-08-17
    • 1970-01-01
    • 2011-01-24
    • 2021-03-19
    • 2021-12-21
    • 2020-12-12
    • 1970-01-01
    相关资源
    最近更新 更多