akshay091778

Create a Discord.js v14 giveaway bot.

Requirements:

  • Slash command: /giveaway
  • Inputs:

- Prize - Duration - Number of winners

When users click the ๐ŸŽ‰ Enter button, they are added to the giveaway entry list.

When the giveaway ends:

  • Do NOT randomly select winners.
  • Instead, show the giveaway creator a dropdown menu containing every user who entered.
  • The creator can manually select the winner(s) from the list.
  • Only users who actually entered can be selected.
  • After confirming, announce the selected winner(s) in the giveaway channel and edit the giveaway embed to display the winners.

Use Discord.py v14 with clean, organized code and proper permission checks.

Kodari AI
KodariJul 18 at 5:02 pm 1
GiveawayBot
A Discord giveaway bot featuring slash commands for creating giveaways with custom prize, duration, and winner count. Users enter by clicking a ๐ŸŽ‰ button. When the giveaway ends, the creator selects winners manually from a paginated dropdown of all entrants. Winners are announced in the channel and the giveaway embed is updated to display results. Persistent storage and background task for automatic expiration.

Iโ€™ll create a clean giveaway bot with a cog-based structure

A Discord giveaway bot with slash commands and manual winner selection. Features include interactive giveaway creation with prize, duration, and winner count inputs. Users enter giveaways by clicking a ๐ŸŽ‰ button. When the giveaway ends, the creator selects winners from a multi-page dropdown menu containing all entrants. Winners are announced in the channel. Persistent storage across bot restarts with automatic recovery of active giveaways.
akshay091778

fix

๐Ÿ“Ž 1 file 1,593 chars
๐Ÿ“„
pasted-code-1784394465777.txt
txt 32 lines
โ–ถ
Traceback (most recent call last):
File "/usr/local/lib/python3.12/site-packages/discord/http.py", line 839, in static_login
data = await self.request(Route('GET', '/users/@me'))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/discord/http.py", line 773, in request
raise HTTPException(response, data)
discord.errors.HTTPException: 401 Unauthorized (error code: 0): 401: Unauthorized
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/root/bot.py", line 32, in 
asyncio.run(main())
File "/usr/local/lib/python3.12/asyncio/runners.py", line 195, in run
return runner.run(main)
^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/asyncio/runners.py", line 118, in run
return self._loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/asyncio/base_events.py", line 691, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "/root/bot.py", line 27, in main
await bot.start(TOKEN)
File "/usr/local/lib/python3.12/site-packages/discord/client.py", line 846, in start
await self.login(token)
File "/usr/local/lib/python3.12/site-packages/discord/client.py", line 675, in login
data = await self.http.static_login(token)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/discord/http.py", line 843, in static_login
raise LoginFailure('Improper token has been passed.') from exc
discord.errors.LoginFailure: Improper token has been passed.
Bot process crashed
Bot stopped
Kodari AI
KodariJul 18 at 5:07 pm 1

The bot token is invalid. Set your real bot token in .env.

The token in .env is still the placeholder your_discord_bot_token_here. Replace it with your real bot token from the Discord Developer Portal:

Plain Text
DISCORD_TOKEN=MTI5Njg3OTk0Njg3OTk0Njg3OTk0Njg3OTk0Njg3OTk0Njg3OTk0

Then run the bot again.

Kodari can make mistakes. Review important code before using.
Files
cogs
bot.py
requirements.txt
Code
4 425
bot.py
import os
import discord
from discord.ext import commands
from dotenv import load_dotenv

load_dotenv()

TOKEN = os.getenv("DISCORD_TOKEN")
if not TOKEN:
    raise ValueError("DISCORD_TOKEN not found in .env file")

intents = discord.Intents.default()
intents.message_content = True

bot = commands.Bot(command_prefix="!", intents=intents, help_command=None)


@bot.event
async def on_ready():
    print(f"Logged in as {bot.user} (ID: {bot.user.id})")
    print("------")


async def main():
    async with bot:
        await bot.load_extension("cogs.giveaway")
        await bot.start(TOKEN)


if __name__ == "__main__":
    import asyncio
    asyncio.run(main())