-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
58 lines (48 loc) · 2.23 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import discord
from discord.ext import commands
import asyncio
import random
# Define intents
intents = discord.Intents.default()
intents.messages = True # Enable message content intent
intents.message_content = True # For message content access in guilds
intents.reactions = True
intents.guilds = True
# Initialize the bot with the new prefix
bot = commands.Bot(command_prefix='g', intents=intents)
@bot.event
async def on_ready():
activity = discord.Activity(type=discord.ActivityType.watching, name=" Code By MohamedLunar & Dummylot")
await bot.change_presence(activity=activity)
print(f'Logged in as {bot.user} successfully')
@bot.event
async def on_command_error(ctx, error):
if isinstance(error, commands.MissingPermissions):
await ctx.send("I don't have enough permissions to run this command!")
elif isinstance(error, commands.BotMissingPermissions):
await ctx.send("I am missing some permissions in this server!")
else:
await ctx.send(f"An error occurred: {error}")
@bot.command(name='!help')
async def help(ctx):
embed = discord.Embed(title="Giveaway Help Menu", description=f'```g!start <duration in seconds> <prize>```', color=0x00FF00)
await ctx.send(embed=embed)
@bot.command(name='!start')
async def start_giveaway(ctx, duration: int, *, prize: str):
embed = discord.Embed(title='🎉 Giveaway 🎉', description=f'Prize: {prize}', color=0x00ff00)
embed.add_field(name='Hosted by:', value=ctx.author.mention)
embed.add_field(name='Ends in:', value=f'{duration} seconds')
embed.set_footer(text='React with 🎉 to enter!')
giveaway_message = await ctx.send(embed=embed)
await giveaway_message.add_reaction('🎉')
await asyncio.sleep(duration)
giveaway_message = await ctx.channel.fetch_message(giveaway_message.id)
users = [user async for user in giveaway_message.reactions[0].users()]
users.remove(bot.user) # Remove bot from the list
if len(users) > 0:
winner = random.choice(users)
await ctx.send(f'🎉 Congratulations {winner.mention}, you won the **{prize}**!')
else:
await ctx.send('🎉 No one participated in the giveaway.')
# Remember to replace 'TOKEN' with your bot's token
bot.run('TOKEN')