-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
65 lines (51 loc) · 2.16 KB
/
app.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
59
60
61
62
63
64
65
# @Stagnant09 2024
# Discord Bot
import discord
from discord import app_commands
from discord.ext import commands
import asyncio
emojis_ = {
"👍": 1,
"👎": -1,
}
# Read env.env and get token
with open('env.env', 'r') as file:
TOKEN = file.read().strip()
intents = discord.Intents.all()
intents.members = True
# Use slash commands
bot = discord.Client(intents=intents)
tree = app_commands.CommandTree(bot)
@bot.event
async def on_ready():
print(f'{bot.user.name} has connected to Discord!')
@tree.command(name="hey", description="Say hello to the bot")
async def hey(ctx):
await ctx.response.send_message(f"Hello, {ctx.user}!")
@bot.event
async def on_connect():
await tree.sync(guild=discord.Object(id=1068860796840448010))
print("Commands registered successfully.")
@tree.command(name="user", description="Calculates the score of a user based on the reactions he/she has received.", guild=discord.Object(id=1068860796840448010))
async def user(interaction: discord.Interaction, arg: str):
await interaction.response.send_message(f"**Calculating {arg}'s score...**", ephemeral=True)
bot.loop.create_task(calculateScore(interaction, arg))
async def calculateScore(interaction: discord.Interaction, user: str):
idd = 0
score = 0
for channel in bot.get_all_channels():
if channel.type == discord.ChannelType.text:
# Make an iterable object from channel.history(limit=100)
async for message in channel.history(limit=2000):
if message.author.name == user:
idd += 1
print(user + "\'" + " message " + str(idd))
for reaction in message.reactions:
if isinstance(reaction.emoji, str):
emoji_name = reaction.emoji
else:
emoji_name = reaction.emoji.name
if emoji_name in emojis_:
score += emojis_[emoji_name]
await interaction.followup.send(f"**{user}'s score is {score}**.\n" + "R/M ratio = " + str(score / idd))
bot.run(TOKEN)