【发布时间】:2021-05-25 21:59:36
【问题描述】:
一切正常 - 嵌入发送但计时器不起作用,并且在赠品结束时编辑消息。这是我的错误:
Ignoring exception in command giveaway:
Traceback (most recent call last):
File "C:\Users\HP\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "c:\Users\HP\Desktop\222\dscbot-dscbot.py", line 70, in giveaway
users = await msg.reactions[0].users().flatten()
IndexError: list index out of range
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\HP\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\bot.py", line 902, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\HP\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 864, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\HP\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: IndexError: list index out of range
如果有人可以发送此代码但已编辑,我将不胜感激。我知道这个问题可能不清楚我是 discord.py 的新手。
from asyncio import sleep
from discord.ext import commands
import discord
from discord import Embed, TextChannel
intents = discord.Intents.default()
intents.members = True
client = commands.Bot(command_prefix = "-", intents = intents)
@client.command()
@commands.guild_only()
@commands.has_permissions(administrator=True)
async def giveaway(ctx, duration: int, channel: discord.TextChannel, *, prize: str):
reaction = discord.Reaction
embed = Embed(title=prize,
description=f"Hosted by - {ctx.author.mention}\nReact with :tada: to enter!\nTime Remaining: **{duration}** seconds",
color=ctx.guild.me.top_role.color,)
msg = await ctx.channel.send(content=":tada: **GIVEAWAY** :tada:", embed=embed)
await msg.add_reaction("????")
users = await msg.reactions[0].users().flatten()
users.pop(users.index(ctx.guild.me))
while duration:
await sleep(2)
duration -= 2
embed.description = f"Hosted by - {ctx.author.mention}\nReact with :tada: to enter!\nTime Remaining: **{duration}** seconds"
await msg.edit(embed=embed)
winner = random.choice(users)
await ctx.send(f"**Congrats to: {winner}!**")
embed.description = f"Winner: {winner.mention}\nHosted by: {ctx.author.mention}"
await msg.edit(embed=embed)
client.run('TOKEN')
【问题讨论】:
-
你能添加整个回溯吗?
-
添加了@ŁukaszKwieciński
-
欢迎来到 StackOverflow !提出问题的目的不是让其他人为您编写代码,而是帮助您(和其他人)更好地了解发生了什么以及使其工作的解决方案。您能否通过生成 minimal, reproducible example 而不是整个代码来帮助我们?
-
@carmeldev 这似乎不是完整的追溯
-
关于包含完整回溯的cmets是因为回溯包含诊断和解决问题的有价值信息。虽然错误消息很有帮助,但回溯包含各种其他信息,例如导致错误的行。
标签: python discord discord.py