@21natzil/

discordy

Python

An attempt at making a discord library

fork
loading
Files
  • main.py
  • discordy
  • requirements.txt
  • setup.py
  • test.png

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.6022006076435675","path":"main.py","file":{"path":"main.py","content":{"asEncoding":{"base64":"ZnJvbSBkaXNjb3JkeS5vYmplY3RzLnNub3dmbGFrZSBpbXBvcnQgU25vd2ZsYWtlT2JqCnMgPSBTbm93Zmxha2VPYmooNTA4MzU2NTI1OTgzNzkzMTUyKQpwcmludChzLnRpbWVzdGFtcCkKCmltcG9ydCB0aW1lCgppbXBvcnQgbG9nZ2luZwoKbG9nZ2luZy5iYXNpY0NvbmZpZygpCmxvZ2dpbmcuZ2V0TG9nZ2VyKCkuc2V0TGV2ZWwobG9nZ2luZy5ERUJVRykKcmVxdWVzdHNfbG9nID0gbG9nZ2luZy5nZXRMb2dnZXIoInJlcXVlc3RzLnBhY2thZ2VzLnVybGxpYjMiKQpyZXF1ZXN0c19sb2cuc2V0TGV2ZWwobG9nZ2luZy5ERUJVRykKcmVxdWVzdHNfbG9nLnByb3BhZ2F0ZSA9IFRydWUKCnRyeToKICAgIGltcG9ydCBodHRwLmNsaWVudCBhcyBodHRwX2NsaWVudApleGNlcHQgSW1wb3J0RXJyb3I6CiAgICAjIFB5dGhvbiAyCiAgICBpbXBvcnQgaHR0cGxpYiBhcyBodHRwX2NsaWVudApodHRwX2NsaWVudC5IVFRQQ29ubmVjdGlvbi5kZWJ1Z2xldmVsID0gMQoKZnJvbSBkaXNjb3JkeS5hcGkuY2hhbm5lbHMgaW1wb3J0IENoYW5uZWwKZnJvbSBkaXNjb3JkeS5jbGllbnQgaW1wb3J0IENsaWVudApmcm9tIGRpc2NvcmR5LmFwaS5ndWlsZCBpbXBvcnQgR3VpbGQKZnJvbSBkaXNjb3JkeS5vYmplY3RzLmdhdGV3YXkuZXZlbnRzIGltcG9ydCBSZWFkeUV2ZW50LCBNZXNzYWdlQ3JlYXRlRXZlbnQs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lbWl0dGVyLmFkZF9saXN0ZW5lcihPblJlYWR5KQpjbGllbnQuZW1pdHRlci5hZGRfbGlzdGVuZXIoT25NZXNzYWdlKQoKY2xpZW50LnJ1bl9mb3JldmVyKCkK"},"asBuffer":null},"loaded":true}}
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
from discordy.objects.snowflake import SnowflakeObj
s = SnowflakeObj(508356525983793152)
print(s.timestamp)

import time

import logging

logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)
requests_log = logging.getLogger("requests.packages.urllib3")
requests_log.setLevel(logging.DEBUG)
requests_log.propagate = True

try:
    import http.client as http_client
except ImportError:
    # Python 2
    import httplib as http_client
http_client.HTTPConnection.debuglevel = 1

from discordy.api.channels import Channel
from discordy.client import Client
from discordy.api.guild import Guild
from discordy.objects.gateway.events import ReadyEvent, MessageCreateEvent, MessageReactionAddEvent
from discordy.objects.gateway.commands import UpdateStatusObj
from discordy.objects.gateway.presence import ActivityObj

client = Client()


class OnReady(ReadyEvent):

  def run(self):
    print("Ready!", self.user.username)
    presence = UpdateStatusObj(
      game = ActivityObj(
        name="Testing Presence!",
        type=0
      ),
      status = "online",
      ask = False
    )
    client.set_presence(presence)


class OnMessage(MessageCreateEvent):

  def run(self):
    if self.content.startswith("=ping"):
      print("Pong!")
      self.respond("Pong!")
    elif self.content.startswith("=test_img"):
      with open('test.png', 'rb') as file:
        self.respond('IMG', stream=('test.png', file))
    elif self.content.startswith('=test_reaction'):
      msg = self.respond("Test Reaction: 🔥")
      msg.react("🔥")
      time.sleep(5)
      msg.remove_reaction("🔥")
    elif self.content.startswith("=add_emoji"):
      name = '_'.join(self.content.split(' ')[1:])
      if not name:
        self.respond("Please enter a name for emoji")
      try:
        print(type(self.author.name), type(self.author.id))
        reaction = client.emitter.wait_for(MessageReactionAddEvent, 8, message_id=self.id, user_id=self.author.id)
      except TimeoutError:
        return self.respond("Sorry, you took to long to react!")
      reaction.emoji.add_to("446740837515395072", "test")
      self.respond("Added the emoji!")
    elif self.content.startswith("=make_guild"):
      name = ' '.join(self.content.split(' ')[1:])
      new_guild = Guild.create_guild(name)
      inv = Channel.create_invite(new_guild.system_channel_id, 1)
      print(inv.code)

    elif self.content.startswith("=invite"):
      guild_id = self.content.split(' ')[1]
      inv = Guild.get_invites(guild_id)
      self.respond(','.join([i.code for i in inv]))
    elif self.content.startswith('=count'):
      _, msg_id, emoji = self.content.split(' ')
      e_name = emoji[1:len(emoji)-1]
      msg = Channel.get_message(self.channel_id, msg_id)
      self.respond(str(len(msg.get_reactions(e_name))))

    elif self.content.startswith('=echo'):
      msg = ' '.join(self.content.split(' ')[1:])
      member = self.channel
      # print(member.guild_id)
      print(dir(member))
      perms = self.channel.apply_permission(member)
      if perms & 0x00000008 == 0x00000008:
        self.respond(msg)
      else:
        self.respond("Invalid Permissions")

client.emitter.add_listener(OnReady)
client.emitter.add_listener(OnMessage)

client.run_forever()