-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOneBot-Niko-Discord.py.old
65 lines (46 loc) · 1.84 KB
/
OneBot-Niko-Discord.py.old
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
#!/usr/bin/env python3
"""
Copyright (C) 2019 Peter Maar
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
from discord.ext import commands
import os
token_path = os.path.normpath('ID/DISCORD_BOT_TOKEN.txt')
TOKEN = str.rstrip(open(token_path).read()) # Load Token from file, removing trailing whitespace
description = '''a test python bot'''
bot = commands.Bot(command_prefix='?', description=description)
@bot.event
async def on_ready():
print('Niko has logged in as')
print(bot.user.name)
print(bot.user.id)
print('------')
@bot.command()
async def add(left : int, right : int):
"""Adds two numbers together."""
await bot.say(left + right)
@bot.command(pass_context=True)
async def ping(ctx):
"""Pong!"""
t = await bot.say('Calculating...')
ms = (t.timestamp-ctx.message.timestamp).total_seconds() * 1000
await bot.edit_message(t, new_content='Pong! Took: {}ms'.format(int(ms)))
@bot.listen()
async def on_message(message):
if message.author.bot: # If the bot sent the message
return # Don't do anything with it
if message.content.startswith('!hello'):
await bot.say("test")
content = 'confused cat noises'
msg = '{0.mention}, {1}'.format(message.author, content)
await bot.send_message(message.channel, msg)
bot.run(TOKEN)