首页 > 解决方案 > 日志命令列表 .append() 在 discord.py 中不起作用

问题描述

我正在使用 discord.py 制作 Discord Bot。
由于某种原因.append()不适用于 log 变量。

它给了我这个错误:

AttributeError: 'Command' object has no attribute 'append'

我在没有 discord.py 的普通脚本上对其进行了测试,并且成功了。
但是由于某种原因,如果我将脚本放在机器人上,它会说


命令代码:

global log
log = ["Spam Log :"]

@client.command()
async def spam(ctx, speed=None, *text):
  global log
  log.append(f"{text} - Spammed By {ctx.author} at {speed} speed.")
  if speed == None:
    await ctx.send("Please put a speed and text")
    return
  try:
    if str(ctx.guild.id) == "854947008304119809" and str(ctx.channel.id) == "868123051030638652":
      import asyncio
      global spamming
      spamming = True
      while spamming == True:
        await ctx.send(" ".join(text[:]))
        await asyncio.sleep(int(speed))
    else:
      await ctx.send("Please do it on <#868123051030638652>.")
        
  except:
    text = "An error accured, please try again with valid numbers."
    await ctx.send(text)
    ```

标签: pythonlistdiscord.pyappend

解决方案


推荐阅读