-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.py
59 lines (41 loc) · 1.51 KB
/
client.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
import discord
from discord.ext import commands
import json
token = "NDc3MTY4Mzc3NTA5NzA3Nzc2.W2x7rg.3Nx4G5wwqrHeMqU3Hjy7NFrmoFE"
def get_prefix(client, message): # get the prefix of a server and use it only in the server!
with open("prefixes.json", "r") as f:
prefixes = json.load(f)
return prefixes[str(message.guild.id)]
client = commands.Bot(command_prefix=get_prefix)
@client.event
async def on_ready():
# login of client
await client.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name='!help'))
print('{0.user} just unleashed!'.format(client))
@client.event
async def on_guild_join(guild):
with open("prefixes.json", "r") as f:
prefixes = json.load(f)
prefixes[str(guild.id)] = "."
with open("prefixes.json", "w") as f:
json.dump(prefixes, f, indent=4)
@client.event
async def on_guild_remove(guild):
with open("prefixes.json", "r") as f:
prefixes = json.load(f)
prefixes.pop(str(guild.id))
with open("prefixes.json", "w") as f:
json.dump(prefixes, f, indent=4)
@client.command()
async def changeprefix(ctx, prefix="-1"):
if (prefix == "-1"):
await ctx.send("You need to specify your prefix!")
prefix = "."
return
with open("prefixes.json", "r") as f:
prefixes = json.load(f)
prefixes[str(ctx.guild.id)] = prefix
with open("prefixes.json", "w") as f:
json.dump(prefixes, f, indent=4)
await ctx.send(f"Prefix changed to {prefix}")
client.run(token)