-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessage.py
67 lines (54 loc) · 2.2 KB
/
message.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
66
67
import os
import discord
from dotenv import load_dotenv
load_dotenv()
intents = discord.Intents.default()
intents.guilds = True
intents.messages = True
intents.message_content = True
client = discord.Client(intents=intents)
# Target channel name and message content
TARGET_CHANNEL_NAME = "general"
MESSAGE_CONTENT = (
"Official Trailer Released for Clodbot: https://www.youtube.com/watch?v=CB3H_Uw3y9g"
)
EXCLUDED_SERVER_NAME = "Paradox Parlor Draft League"
SPECIAL_SERVER_NAMES = ["BATTLE FRONTIER GTA", "Clodbot"]
@client.event
async def on_ready():
print(f"Logged in as: {client.user.name} (ID: {client.user.id})")
for guild in client.guilds:
# Skip the excluded server
if guild.name == EXCLUDED_SERVER_NAME:
print(f"Skipping server: {guild.name} (ID: {guild.id})")
continue
print(f"Processing server: {guild.name} (ID: {guild.id})")
# Look for the first 'general' channel in the current server
target_channel = discord.utils.find(
lambda c: c.name == TARGET_CHANNEL_NAME and isinstance(c, discord.TextChannel),
guild.text_channels,
)
if target_channel:
try:
# Use @everyone for special servers
if guild.name in SPECIAL_SERVER_NAMES:
message = f"@everyone {MESSAGE_CONTENT}"
else:
message = MESSAGE_CONTENT
# Send the message to the 'general' channel
await target_channel.send(message)
print(f"Message sent to {TARGET_CHANNEL_NAME} in {guild.name}.")
except discord.Forbidden:
print(f"Permission denied for channel {TARGET_CHANNEL_NAME} in {guild.name}.")
except discord.HTTPException as e:
print(f"Failed to send message to {TARGET_CHANNEL_NAME} in {guild.name}: {e}")
else:
print(f"Channel '{TARGET_CHANNEL_NAME}' not found in {guild.name}.")
print("All messages sent. Closing connection.")
await client.close()
# Get the bot token from the .env file
token = os.getenv("DISCORD_BOT_TOKEN")
if token:
client.run(token)
else:
print("Token not found. Please check your .env file.")