forked from FlareHD/checkwhatserversdiscordbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
73 lines (63 loc) · 2.64 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import discord
intents = discord.Intents.default()
intents.message_content = True
client = discord.Client(intents=intents)
spaceString = " "
@client.event
async def on_ready():
print(f'We have logged in as {client.user}')
# start the discord bot
@client.event
async def on_message(message):
if message.author == client.user:
return
#Displays total list of servers the bot is in with server IDs:
if message.content.startswith('$servers'):
serverListString = ""
for guild in client.guilds:
serverListString = serverListString + guild.name + ": " + str(guild.id) + "\n"
await message.channel.send(serverListString)
# Displays the channels in a specified server:
if message.content.startswith('$channels'):
serverID = message.content.split(spaceString)[1]
guild = client.get_guild(int(serverID))
strChannels = "" + guild.name + "\n"
printIDs = " " + guild.name + "\n"
#PrintIDs logs the channel name and ID to the console; whereas only sending channel names on discord:
for channel in guild.channels:
strChannels = strChannels + channel.name + "\n"
printIDs = printIDs + channel.name + " " + str(channel.id) + "\n"
strChannels = strChannels[0:2000]
await message.channel.send(strChannels)
print(printIDs)
#Send a message to a discord server channel:
channelID = ""
content = ""
if message.content.startswith("$send"):
channelID = message.content.split(spaceString)[1]
content = spaceString.join(message.content.split(spaceString)[2:])
print(channelID)
print(content)
channel = client.get_channel(int(channelID))
await channel.send(content)
#Send users a bot DM:
userID = ""
dmcontent = ""
if message.content.startswith("$dm"):
userID = message.content.split(spaceString)[1]
dmcontent = spaceString.join(message.content.split(spaceString)[2:])
print(userID)
print(dmcontent)
user = await client.fetch_user(userID)
await user.send(dmcontent)
await message.channel.send
# Shows DM content to bot:
if message.guild is None and not message.author.bot:
channel = client.get_channel(int(1251944380114141244))
await channel.send(f'DM from {message.author}: {message.content}')
# Leave a specified discord server:
if message.content.startswith("$leave"):
serverID = message.content.split(spaceString)[1]
guild = client.get_guild(int(serverID))
await guild.leave()
client.run('nonono upload ur own token')