所以基本上我正在尝试为我的不和谐机器人创建一个垃圾邮件命令,它将自定义消息接收为垃圾邮件。代码如下:
@client.command(name='spam')
async def spam(ctx):
global stop
stop = 0
content = ctx.message.content[11:]
if ctx.author.guild_permissions.administrator or ctx.author.id in admins:
if lock == 1:
await ctx.send('Jesus bot is currently locked.')
elif lock == 0:
await ctx.send('Beginning spam..')
while not stop:
await ctx.send(content)
else:
await ctx.send('Sorry, but you do not have admin permissions in this server, or you are not a verified admin.')
出于某种原因,每当我尝试使用此命令时,机器人都没有响应。我不确定为什么会发生这种情况,请提供一些帮助。
机器人没有响应的图片:
答案 0 :(得分:0)
我有一个垃圾邮件命令,但我只用它来惹我的朋友。我不建议将其用作公共命令,因为您可能会因滥用或类似原因而受到限制或禁止。无论如何,这是我用于它的代码。
@commands.command()
@commands.is_owner()
# If you want to use admin only, use this below
# @commands.has_permissions(administrator=True)
async def spam(self, ctx, amount, *, word):
int(amount)
await asyncio.sleep(2)
print(f"Starting to spam {word} in {ctx.guild.name}")
await ctx.message.delete()
await ctx.send(f"{ctx.author.mention}\nPlease note that this will clog up the bot's reaction time")
await asyncio.sleep(3)
count = 0
counting=True
while counting:
await ctx.send(word)
count = count + 1
if count == amount:
await asyncio.sleep(2)
await ctx.send("Spam complete")
print(Fore.GREEN + "Spam complete")
counting = False
在代码的顶部,确保导入 asyncio,因为 time.sleep 会导致整个机器人暂停。 Fore.GREEN 的东西也只是 colorama(导入 colorama)。
答案 1 :(得分:0)
尝试使用 tasks 代替 asyncio。它是为这样的重复操作而制作的,它更容易和更好,因为它是由 discord 制作的,并且包含在 discord.ext
中。像这样:
from discord.ext import tasks
@client.command(name='spam')
async def spam(ctx):
#get message and do all the ifs that you have there
spamLoop.start()
@client.command(name='stopSpam')
async def spamStop(ctx):
# stop the loop
spamLoop.cancel()
@tasks.loop(seconds=1)
async def spamLoop():
print("The message")