一切正常-嵌入发送,但定时器不工作,编辑消息,而赠品结束。这是我的错误:
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')
格式化时您犯了一些错误
discord.Embed
定义的,而不仅仅是Embed
await sleep
不应使用,而应使用await asyncio.sleep
李>reaction = discord.Reaction
实际上不是一个调用,甚至没有在代码中使用,所以我也删除了channel: discord.TextChannel
李>看起来你要求的反应也是错误的。我有一个类似的问题,并改变了你的代码一点
我们现在使用不同的方法,而不是
users = await msg.reactions[0].users().flatten()
:因此,这里的新功能是,我们实际上
fetch
通过ID调用消息,这是一个API调用,但是我们得到了我们需要的所有信息如果您只想编辑已发布的消息,只需使用以下命令:
相关问题 更多 >
编程相关推荐