简体   繁体   English

对如何让 discord bot 发送一定数量的消息感到困惑?

[英]Confused on how to make discord bot send a certain amount of messages?

I'm trying to make a small spambot with discord.js, as one of my first python bots.我正在尝试使用 discord.js 制作一个小型垃圾邮件机器人,作为我的第一个 python 机器人之一。 It honestly works fine, but there's one problem.老实说,它运行良好,但有一个问题。 The bot is supposed to spam every channel in a server, but it only sends one message.该机器人应该向服务器中的每个频道发送垃圾邮件,但它只发送一条消息。 I don't know python that well, and I know where the problem is and what I need to do to fix it, I just don't know how to fix it.我不太了解python,我知道问题出在哪里以及我需要做什么来修复它,我只是不知道如何修复它。 I'm guessing I need to put an amount of messages that I want the bot to send, but I don't know how to do that.我猜我需要放置一些我希望机器人发送的消息,但我不知道该怎么做。 I'm hoping someone can help!我希望有人可以提供帮助! (PS I'm not using the bot for anything bad, I just wanna test it out.) Anyway, here's my code: (PS 我不会使用机器人做任何坏事,我只是想测试一下。)无论如何,这是我的代码:

@bot.command()
async def sall(ctx, *, message=None):
    if message == None:
        for channel in ctx.guild.channels:
            try:
                await channel.send(random.choice(spam_messages))
            except discord.Forbidden:
                print(f"{C.RED}Spam Error {C.WHITE}[Cannot send messages]")
                return
            except:
                pass
    else:
        for channel in ctx.guild.channels:
            try:
                await channel.send(message)
            except discord.Forbidden:
                print(f"{C.RED}Sall Error {C.WHITE}[Cannot send messages]")
                return
            except:
                pass

Well, you really only send one message!嗯,你真的只发一条消息!

@bot.command()
@bot.is_owner()
async def sall(ctx, *, message=None):
    if message == None:
        for channel in ctx.guild.channels:
            try:
                for i in range(10):
                    await channel.send(random.choice(spam_messages))
            except discord.Forbidden:
                print(f"{C.RED}Spam Error {C.WHITE}[Cannot send messages]")
                return
            except:
                pass
    else:
        for channel in ctx.guild.channels:
            try:
                for i in range(10):
                    await channel.send(message)
            except discord.Forbidden:
                print(f"{C.RED}Sall Error {C.WHITE}[Cannot send messages]")
                return
            except:
                pass

It should work like this.它应该像这样工作。 I added a for i in range(10) , what it does is, it repeats this 10 times.我添加了一个for i in range(10) ,它的作用是,它重复了 10 次。 So just change it to number of times you want it to send a message.因此,只需将其更改为您希望它发送消息的次数即可。

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

相关问题 如何使 discord 机器人删除机器人发送的消息 - How to make discord bot delete messages send by the bot 如何让 discord.py bot 随机发送消息 - How to make discord.py bot send messages at random times Discord.py 如何让机器人在特定时间后删除消息 - Discord.py How can I make a bot delete messages after a specific amount of time 如何让我的 discord 机器人每隔几秒发送一次消息?(discord.py) - How to make my discord bot send messages every few seconds?(discord.py) Discord.py Bot 在特定时间发送消息 - Discord.py Bot send messages at certain times 如果作者没有特定角色,如何制作一个不和谐的bot来删除带有附件的邮件 - How to make a discord bot which deletes messages with attachments if the author doesn't have certain roles 如何使用 discord.py 制作一个检查某个服务器通道中所有消息的机器人 - How do I use discord.py to make a bot that checks through all messages in a certain server channel 如何让我的机器人在响应来自 discord 的消息时发送嵌入 - How do i make my bot send embeds when responding to messages from discord 如何让我的 discord 机器人从 a.txt 文件(python)发送消息 - How can I make my discord bot send messages from a .txt file (python) 用 Python 编写一个 Discord 机器人 - 如何让它自动发送消息? - Programming a Discord bot in Python- How do I make it automatically send messages?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM