-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubjapanbot.py
More file actions
78 lines (67 loc) · 2.92 KB
/
subjapanbot.py
File metadata and controls
78 lines (67 loc) · 2.92 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
import discord
import os
from bot_config import *
bot_channel = bot_channel_id
token = os.environ['TOKEN']
client = discord.Client()
errorMsg = 'En feil har oppstått. Kontakt administrator! エラーが発生しまいました!管理人に連絡してください!'
@client.event
async def on_ready():
print('SubJapanBot running! as {0.user}'.format(client))
@client.event
async def on_member_join(member):
channelid = 696733496592564294
jikoshokai_id = 705063473364729926
jikoshokai = client.get_channel(jikoshokai_id)
channel = client.get_channel(channelid)
mentionstr = member.mention
msg = (f"A wild {mentionstr} has appeared! Gjerne introduser deg i {jikoshokai.mention} - 野生の{mentionstr}が現れた!是非 {jikoshokai.mention} で自己紹介してね")
await channel.send(msg)
@client.event
async def on_message(message):
content = message.content
author = message.author
guild = message.guild
channel = message.channel
if bot_channel == channel.id and author.id != client.user.id and content.startswith('.') and author.bot == False:
if content == '.tasukete':
await print_help(channel, guild)
role = None
for key in role_dict.keys():
if role_dict[key].get(content, False):
role = guild.get_role(role_dict[key][content])
remove_key = key
if role:
if role in author.roles:
await remove_role(channel, author, role)
else:
if not remove_key == "Språkjelp 語学助手":
for role_code in role_dict[remove_key]:
await remove_role(channel, author, guild.get_role(role_dict[remove_key][role_code]), True)
await set_role(channel, author, role)
else:
await channel.send('Skriv .tasukete for hjelp. ヘルプを表示するには .tasukete')
async def set_role(channel, author, role):
try:
print(f'Adding role {role} to {author}')
await author.add_roles(role)
await channel.send(f"Du har fått rollen ( {role} )というロールを付けました。")
except:
await channel.send(errorMsg)
async def remove_role(channel, author, role, silent=False):
try:
print(f"Removing role {role} from {author}")
await author.remove_roles(role)
if not silent:
await channel.send(f"Fjernet rollen: ( {role} )というロールを消しました。")
except:
await channel.send(errorMsg)
async def print_help(channel, guild):
s = "**Skriv . etterfulgt av en rolle for å få rollen. 欲しいロールを.の後に付けたらロールを貰えます** \n"
for key in role_dict.keys():
s += "*" + key + "* ```"
for level in role_dict[key]:
s += level + " -> " + guild.get_role(role_dict[key][level]).name + "\n"
s += "```"
await channel.send(s)
client.run(token)