Giveaway bot discord.py

Everything works fine but when I execute command pops up this:

in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: IndexError: list index out of range

If someone could send this code but edited I would appreciate it. ;)

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')


Read more here: https://stackoverflow.com/questions/66336386/giveaway-bot-discord-py

Content Attribution

This content was originally published by carmel dev at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: