Giter Club home page Giter Club logo

Comments (2)

Jan3kk avatar Jan3kk commented on May 24, 2024

Also, I'm sorry but even after reading most of issues, I don't understand what's the token? I am using email+password to sign in and it works, although in the beginning of testing your library it was sometimes giving error:

`Traceback (most recent call last):
File "C:\Users\xxx\Desktop\discord-karuta-collector\send.py", line 99, in
bot2 = discum.Client(email=email2, password=pass2, log=False)
File "C:\Users\xxx\Desktop\discord-karuta-collector\venv\lib\site-packages\discum\discum.py", line 73, in init
self.__user_token, self.__xfingerprint = Login(self.s, self.discord, self.log).GetToken(email=email, password=password, secret=secret, code=code) #update token from "" to actual value
File "C:\Users\xxx\Desktop\discord-karuta-collector\venv\lib\site-packages\discum\start\login.py", line 53, in GetToken
self.__token = result['token']
KeyError: 'token'

Process finished with exit code 1`

Aren't tokens meant to be used in public API bots?

btw:
I'm asking this in second comment because I started to upgrade my bots and I am still having this issue.


arandomnewaccount:
hey, for your first comment, you've almost got it. Here's what I'm thinking based on the info you provided:

bot.sendMessage(channel_ID, "k!c")

@bot.gateway.command
def helloworld(resp, channel_ID='1293823982347'):
    if resp.event.message: #if MESSAGE_CREATE event
        m = resp.parsed.auto()
        if m['author']['id'] == '646937666251915264':
            msg_ID = m['id']
            bot.addReaction(channel_ID, msg_ID, "✅")

bot.gateway.run()

1st, the message is sent. Then the function, helloworld, is appended onto the gateway command list. All this function does is check if the author of new msgs == '646937666251915264' and then adds a reaction if that's the case. You could add more checking (channel id checks, guild id checks, whatever, if you want).

as for your second comment, email+password is ok. The problem is that when logging in on your default ip, sometimes discord will provide a captcha challenge. Therefore, logging in with email+password isn't as predictable as simply providing the token (which is why I'd recommend to just use your token).

Aren't tokens meant to be used in public API bots?

Both user accounts and bot accounts use tokens. When you successfully login to discord with your email+password, discord sends you your user token.

btw here's a nice screenshot from Dracovian/Discord-Scraper that shows where to find your user token: https://camo.githubusercontent.com/cdca341328496fee49e06f53b4805706587237785e5362c90f64ed4fa97c704c/68747470733a2f2f692e696d6775722e636f6d2f6f3953663043482e706e67

from discord-s.c.u.m.

Jan3kk avatar Jan3kk commented on May 24, 2024

Okay, thanks for the token tutorial, but with the first problem I think I didn't make it clear enough, because I am already using exact method you suggested in your response. Unfortunately, that way doesn't allow me to make long, chained conversations. I would like to know a way to block code executed in event-functions until I get a new event, something like this:

@bot1.gateway.command def react_(resp): if resp.raw['d']['content'] == "xxx": bot.sendMessage(channel_ID, "k!mt <@my_main_acc_id>") new_response = await react_() # <----- this code blocks execution of the rest of the code in a way that it waits for # another message that would contain for example "yyy" in resp.raw['d']['content'] if new_response['d']['content'] == "yyy": bot.addReaction(channel_ID, new_response['d']['id'], "✅") else: bot.addReaction(channel_ID, new_response['d']['id'], "🔒")
I'm sorry for the formatting but I don't know why TABs disappear, here's formatted one on pastebin.

To make it even more clear for you, here's an real-life example:

me = my bot
a friend of mine = karuta bot

  1. I send a letter to my friend using mail (paper, handwritten) with a question: "Can I borrow x from you?"
  2. I wait for the reply # This would be await in the code
  3. After x time, I get a letter with:
    • "yes":
      a) I send back a letter "thanks"
    • "no":
      a) I send back a letter "i hate you"

arandomnewaccount:
ah ok, thanks for the clarification. Btw discum uses threading instead of async. Also, the reason why your code formatting is off is because you're using one ` instead of three. About blocking code, I suppose if you really wanted to you could either use a while loop or keep track of some sort of message_stream variable, but I'm not entirely sure that'd be necessary for this problem.

This is an edited version of your code in the pastebin that works:

@bot1.gateway.command 
def react_(resp): #this function will run after each response from discord
	if resp.event.message: #if MESSAGE_CREATE event
		m = resp.parsed.auto() #same thing as resp.parsed.message_create
		if m["content"] == "xxx":
			bot.sendMessage(channel_ID, "k!mt <@"+main_acc_id+">") 
		elif m["content"] == "yyy": 
			bot.addReaction(channel_ID, m["id"], "✅") 
		else:
			bot.addReaction(channel_ID, m["id"], "🔒")

bo1.gateway.run()

After doing a quick check up on katura's msg formatting, I rewrote some stuff. Renamed bot1 to bot and bot to friend (since bot1 seemed to be your main). Therefore, below, bot is your main account:

@bot.gateway.command
def react_(resp, channel_ID="channel_id_here", friend_id="friend_id_here"): #this function will run after each response from discord
	if resp.event.ready_supplemental: #on bot startup
		friend.sendMessage(channel_ID, "k!mt <@"+bot.gateway.session.user["id"]+">") #send initial msg, bot.gateway.session.user["id"] is the bot's user id
	if resp.event.message: #if MESSAGE_CREATE event
		m = resp.parsed.auto() #same thing as resp.parsed.message_create
		target_msg = "<@"+bot.gateway.session.user["id"]+">, would you like to trade with <@"+friend_id+">?"
		if m["author"]["id"]=="646937666251915264" and m["content"]==target_msg: #checks Karuta's id and target_msg match
			bot.addReaction(channel_ID, m["id"], "☑️")
	if resp.event.message_updated: #message update event
		edited_m = resp.parsed.auto()
		if "This trade session will expire in 10 minutes." in edited_m["embeds"][0]["description"]:
			friend.addReaction(channel_ID, edited_m["id"], "🔒")
			bot.addReaction(channel_ID, edited_m["id"], "🔒")
		elif "This trade has been locked." in edited_m["embeds"][0]["description"]:
			friend.addReaction(channel_ID, edited_m["id"], "✅")
			bot.addReaction(channel_ID, edited_m["id"], "✅")

bot.gateway.run()

Simply, what's happening above is after your bot connects to discord's gateway, your bot sends the k!mt command to the channel. Katura responds with a message (and we can check the contents of that msg). If everything looks good, a ☑️ reaction is made by your friend. After that, Katura edits the embed to include This trade session will expire in 10 minutes., so, we check for that and add the locked reaction with both accounts. After that, This trade has been locked. is edited into the embed and we check for that and react accordingly.

For some of these event-driven problems, if given the right conditionals, sequential data doesn't need to be considered. But, if you do need to check for something that occurred in an event in the past (like, a specific trade from katura that happened an hour ago, you can save them into instance variables and check them later that way.

edit: lemme know if that helps

No response so I'm closing this for now. Feel free to open another issue if you have other questions about this.

from discord-s.c.u.m.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.