This repository was archived by the owner on Apr 2, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
74 lines (55 loc) · 2.41 KB
/
Copy pathbot.py
File metadata and controls
74 lines (55 loc) · 2.41 KB
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
66
67
68
import discord
from discord import app_commands
from discord.ext import commands
import responces # Assuming you have this module for responses
from config import token_discord
async def send_message(message, user_message, is_private):
try:
response = responces.handle_response(user_message)
await message.author.send(response) if is_private else await message.channel.send(response)
except Exception as e:
print(e)
def run_discord_bot():
TOKEN = token_discord
# Define the intents and enable them
intents = discord.Intents.default()
intents.typing = False # Disable typing events if desired
intents.presences = False # Disable presence events if desired
intents.messages = True # Enable message events
intents.message_content = True
# Explicitly enable privileged intents (for members and message content)
intents.members = True
intents.message_content = True
bot = commands.Bot(command_prefix='!', intents=intents)
@bot.event
async def on_ready():
print(f'{bot.user} is now running!')
try:
synced = await bot.tree.sync()
print (f"synced {len(synced)} command(s)")
except Exception as e:
print (e)
@bot.event
async def on_message(message):
if message.author == bot.user:
return
username = str(message.author)
user_message = str(message.content)
channel = str(message.channel)
print(f"Received message in {channel} from {username}: '{user_message}'")
if user_message and user_message[0] == '?':
user_message = user_message[1:]
await send_message(message, user_message, is_private=True)
else:
await send_message(message, user_message, is_private=False)
@bot.tree.command(name="hello")
async def hello(interaction: discord.Interaction):
print(f" hello command from {interaction.user}")
await interaction.response.send_message(f"Hey {interaction.user.mention}! This is a slash command!")
@bot.tree.command(name="say")
@app_commands.describe(thing_to_say = "what should I say")
async def say(interaction: discord.Interaction, thing_to_say: str):
print(f" say command from {interaction.user} saying {thing_to_say}")
await interaction.response.send_message(f"{interaction.user.name} said: `{thing_to_say}` ")
# Run the bot
bot.run(TOKEN)