简体   繁体   English

如何在 discord.py 中发出垃圾邮件命令

[英]How to make a spam command in discord.py

Ive just started learning py today and I want to make a spam command that uses args to choose今天刚开始学py,想做个垃圾邮件命令,用args来选择

  1. how many times to send the message多少次发送消息
  2. what the message is i want to spam我想发送垃圾邮件是什么信息

Ive tried taking peices of other code and bending them to what i need but now im stuck:我尝试过使用其他代码并将它们弯曲到我需要的地方,但现在我卡住了:

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):

So my idea would be: .spam [amount of times] [message to spam]所以我的想法是:.spam [amount of times] [message to spam]

thanks:)谢谢:)

(this is meant to be a selfbot but only to mess around with friends and stuff, im fully aware of the consequences of them but its just for fun) (这本来是一个自我机器人,但只是为了和朋友和东西混在一起,我完全知道他们的后果,但这只是为了好玩)

Pretty simple:很简单:

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')

This defines a command that takes two arguments: an amount as integer and the message you want to send.这定义了一个需要两个 arguments 的命令:数量为 integer 和您要发送的消息。 *, Makes it so the rest of the command is put into message because otherwise it would stop at whitespace. *,使命令的 rest 放入消息中,否则它将在空白处停止。

Example Usage: .spam 2 Hello Sends Hello two times.示例用法: .spam 2 Hello发送 Hello 两次。

You might run into Rate Limits when overdoing this command so take care.过度执行此命令时,您可能会遇到速率限制,因此请小心。

    @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))

Here's one I coded这是我编码的一个

async def spam(ctx, *, num, message)
    await ctx.message.delete()
    for i in range(num):
      await ctx.send(message)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM