【发布时间】:2021-02-06 17:40:47
【问题描述】:
所以我尝试使用 python 为我的 discord 机器人做这个简单的投票功能:
@command(name="makePoll")
@has_permissions(manage_guild=True)
async def createPoll(self, ctx, question, *options):
if len(options) > 10:
await ctx.send("You can only supply a maximum of 10 options.")
else:
embed = Embed(title="Poll",
description=question,
colour=ctx.author.colour,
timestamp=datetime.utcnow())
fields = [("Options", "\n".join([f"{numbers[idx]} {options}" for idx, option in enumerate(options)]), False),
("Instructions", "React to case a vote!", False)]
for name, value, inline in fields:
embed.add_field(name=name, value=value, inline=inline)
await ctx.send(embed=embed)
问题是当我尝试调用该函数时它会抛出一个错误。 错误:忽略命令无中的异常: discord.ext.commands.errors.CommandNotFound:找不到命令“makePoll”。
编辑:试图命名 client.command makepoll 但知道它给了我这个错误:忽略命令 makePoll 中的异常: 回溯(最近一次通话最后): 文件“F:\first try on python\venv\lib\site-packages\discord\ext\commands\core.py”,第 85 行,已包装 ret = 等待 coro(*args, **kwargs) 文件“F:/first try on python/for loop/bot1.py”,第 40 行,在 createPoll 中 颜色=ctx.author.color, AttributeError: 'str' 对象没有属性 'author'
上述异常是以下异常的直接原因:
Traceback(最近一次调用最后一次): 文件“F:\first try on python\venv\lib\site-packages\discord\ext\commands\bot.py”,第 903 行,在调用中 等待 ctx.command.invoke(ctx) 文件“F:\first try on python\venv\lib\site-packages\discord\ext\commands\core.py”,第 859 行,在调用中 等待注入(*ctx.args,**ctx.kwargs) 文件“F:\first try on python\venv\lib\site-packages\discord\ext\commands\core.py”,第 94 行,已包装 从 exc 引发 CommandInvokeError(exc) discord.ext.commands.errors.CommandInvokeError:命令引发异常:AttributeError:'str'对象没有属性'author'
【问题讨论】:
-
你能展示你的进口吗?
-
你可以尝试用
@client.command(name="makePoll")代替@command(name="makePoll")吗? -
import discord, import time, import random, from discord import Embed, from date time, from discord.ext import command, tasks, from itertools import cycle from discord.ext.comand import has_permissions, command
-
@Nurqm 使用了你的方法,但现在它抛出了一个完全不同的错误
-
试试
commands.command(name='makepool')。
标签: python-3.x discord.py