-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
40 lines (30 loc) · 910 Bytes
/
main.py
File metadata and controls
40 lines (30 loc) · 910 Bytes
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
from discord.ext import commands
from dotenv import load_dotenv
from NumberScript.interpreter import Interpreter
import discord
import os
import io
import sys
class custom_stdout:
def __init__(self):
self.real_stdout = sys.stdout
self.new_stdout = io.StringIO()
def write(self, s):
self.real_stdout.write(s)
self.new_stdout.write(s)
def getvalue(self):
return self.new_stdout.getvalue()
load_dotenv(".env")
intents = discord.Intents.default()
intents.message_content = True
bot = commands.Bot(command_prefix='$', intents=intents)
@bot.command(name="ping")
async def ping(ctx):
await ctx.send("Pong!")
@bot.command(name="eval")
async def eval(ctx, *, program):
new_stdout = custom_stdout()
sys.stdout = new_stdout
Interpreter.interpret(Interpreter, code=program)
await ctx.send(new_stdout.getvalue())
bot.run(os.environ["token"])