-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
108 lines (93 loc) · 3.77 KB
/
bot.py
File metadata and controls
108 lines (93 loc) · 3.77 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import discord
#
# Powered by Feylinchen#1234
# inspired by https://github.com/OniSensei/Role-Message-Tracker
# who was inspired by Me ^.^
# open Source Python Variant
#
# Multiple Roles + Channels are supported!
#
# Usage:
# 1. TOKEN = Set your Bot Token
# 2. Modify rolesToWatch by your needs.
# Either use IDs of Roles, to track invisible Roles or use Role Names.
# If you want to use IDs, make sure "useRoleIDs" is True
#
# Example with Names:
# [{'role': 'Developer', 'channels': [ 1088231599025422356, 1088231613298647101], 'blacklistedChannels':[]}]
#
#
# Example with IDs: rolesToWatch = [{'role': 1088148992514338836, 'channels': [ 1088231599025422356,
# 1088231613298647101], 'blacklistedChannels':[]}]
#
# NEW! Use Keyword, to track messages. Add the Keyword INFRONT of your message, to make sure it gets tracked.
#
# To Modify the Style of the Message
# I recommend reading: https://python.plainenglish.io/python-discord-bots-formatting-text-efca0c5dc64a
# Chapter: Multiline Code Blocks
TOKEN = '<Your token here>'
useRoleIds = True
keyword = '!dt'
useKeyword = True
rolesToWatch = [{'role': 1088148992514338836, 'channels': [1088231599025422356, 1088231613298647101],
'blacklistedChannels': [662383121689477151, 362646267974647820]},
{'role': 662383376115957770, 'channels': [1088231675605033040], 'blacklistedChannels': []}]
def search(role, message):
if useRoleIds:
for p in message.author.roles:
if int(p.id) == role:
return True
return False
else:
for p in message.author.roles:
if str(p) == role.strip():
return True
return False
def checkblacklist(channelid, channels):
for channel in channels:
if channel == int(channelid):
print('Forbidden channel, do not track')
return True
return False
def notContainsKeyword(message):
if keyword not in message.content or not message.content.startswith(keyword):
return True
return False
def run_discord_bot():
intents = discord.Intents.all()
client = discord.Client(intents=intents)
@client.event
async def on_ready():
print(f'{client.user} is now running')
@client.event
async def on_message(message):
print("message recieved")
alreadyReplaced = False
if message.author == client.user:
return
for item in rolesToWatch:
# check if the Channel is Blacklisted
if checkblacklist(int(message.channel.id), item.get('blacklistedChannels')):
return
# check for Role and copy message
if search(item.get('role'), message):
channels = item.get('channels')
for cn in channels:
if useKeyword and notContainsKeyword(message):
return
elif not alreadyReplaced:
print("in else")
messageCopy = message.content.replace(keyword, "", 1)
alreadyReplaced = True
channel = client.get_channel(cn)
embed = discord.Embed(
description=messageCopy,
color=discord.Color.blue())
embed.set_author(name=str(message.author)[:-5], # remove [:5] if you want to keep the full
# Discord ID
icon_url="<icon url here>") # URL to your Icon
embed.set_thumbnail(url=message.author.avatar)
embed.add_field(name="Jump to Original Message:", value="[View](" + message.jump_url + ")",
inline=False)
await channel.send(embed=embed)
client.run(TOKEN)