I am trying to read the members of a guild by invitation. As soon as we send a link from a server, information such as name, online membership and total members appears. How do I get this information? (The library in question is discord.py)
Example:
(I can't share an image, so I ask you to open the photo link:)
https://cdn.discordapp.com/attachments/842566116978327584/844421408019841034/unknown.png
Name: ☕|Clube do café #240|☕
Photo url: https://cdn.discordapp.com/icons/828004701148676137/62f745ee62f7fb6dd7fbc34a6b75f2df.png?size=128
Online: 112
Members: 232
Id: 806673124819992688
(I extracted this information manually, but was wondering how to do this in the code)
I have already tried to use the following message attributes: attachments, embeds, guild, stickers and system_content. Both returned empty or the invite link.
This is possible with the help of the fetch_invite() function
invite = await client.fetch_invite(url = "https://discord.gg/Invite-ID")
You can then retrieve your desired attributes
For example:
memberCount = invite.approximate_member_count
presenceCount = invite.approximate_presence_count
guildName = invite.guild.name
guildIcon = invite.guild.icon_url
guildID = invite.guild.id
And so on
Related
I was trying to find the way you can identify embed message text and author, but never found it. So is there any way to do that?
Googled through out of the Internet but not found it unfortunately.
Take a look at the docs here
If you have an Embed object, obj just use obj.author to get the author. The text I'm assuming you mean the title, which can be accessed by obj.title.
Assuming you have a Message object,
First, to get message author:
author = message.author
To get the embed from the message:
embed = discord.Embed.from_data(message.embeds[0]) # gets embed from message
Before getting the embed text, we first look at the attributes of a discord.Embed object. It has the attributes title and description [source].
Therefore:
embedTitle = embed.title # get title
embedDescription = embed.description # get description
I am trying to figure out a way to scan through all the unread messages in a Telegram Channel and download videos and images that have more than certain amount of reactions.
I got to the point where the script will download all the unread videos and images, but I am stuck at how to filter those messages based on reactions. For example: only download the videos and images that have at least 3👍 reactions and/or 3❤️ reactions.
My code is included below. The script downloads all the unread videos and images from the channel title and store them in a sub-folder called title. Like I said, I don't want to download all the videos and images. I only want the ones that meet certain reaction thresholds. Any suggestions or ideas would be greatly appreciated!
title = 'channel name'
with TelegramClient(username, api_id, api_hash) as client:
chat_names = client(GetDialogsRequest(
offset_date=None,
offset_id=0,
offset_peer='username',
limit=0,
hash=0
))
result = client(functions.messages.GetPeerDialogsRequest(
peers=[title]
))
for chat in chat_names.chats:
if chat.title == title:
for message in client.iter_messages(title, limit=result.dialogs[0].unread_count):
if message.photo or message.video:
message.download_media('./' + str(titles) + '/')
There are easier ways to fetch dialogs than using GetDialogsRequest, which is raw API, with client.get_dialogs instead:
# Fetch the first 100 dialogs (remove the 100 to fetch all of them)
# I have renamed `chat_names` with `dialogs` to make it clearer.
dialogs = client.get_dialogs(100)
The second call to GetPeerDialogsRequest is also unnecessary. It's meant to be used when you want to fetch dialog information about a particular user or chat - but you already fetched all dialog information before.
(Technically, we could remove client.get_dialogs and only use GetPeerDialogsRequest, but for simplicity I won't do that.)
To check reactions given a message you can access the message.reactions field (as seen in the raw API for Message):
print(message.reactions.stringify())
This will give you a feel for what the object looks like with your Telethon version, in my case:
MessageReactions(
results=[
ReactionCount(
reaction=ReactionEmoji(
emoticon='❤'
),
count=11,
chosen_order=None
),
...
]
)
So all that's left is checking if a message meets your needs. I'll make a separate function to make it easier to read:
def should_download(message):
if not message.photo or not message.video:
return False # no photo or video, no need to download
if not message.reactions:
return False # no reactions
for reaction in message.reactions.results:
# It might be a ReactionCustomEmoji which doesn't have an emoticon
# Use getattr to read the emoticon field or return None if it doesn't exist
emoticon = getattr(reaction.reaction, 'emoticon', None)
if emoticon in ('❤', '👍') and reaction.count >= 3:
return True # has enough reactions
return False # did not find the reactions we wanted
And finally the loop can use the function:
for dialog in dialogs:
if dialog.title == title:
# We can use the dialog instead of the title as the chat
for message in client.iter_messages(dialog, dialog.unread_count):
if should_download(message):
message.download_media('./' + str(titles) + '/')
Hi stalkers
Is there a way to access a site's data directly?
I need it for my code :
#commands.command(aliases = ['isitsafe','issafe','scanlink'])
async def isthissafe(self, ctx, link: str):
try:
link = 'https://transparencyreport.google.com/safe-browsing/search?url='+ link.replace('/','%2F')
embed=discord.Embed(
color = discord.Color.dark_red(),
title = '',
description = f"[Transparency Report verification]({link})")
await self.emb(embed, ctx.author.name, 'https://cwatch.comodo.com/images-new/check-my-site-security.png')
await ctx.send(embed=embed)
except:
await ctx.send('An error has occured')
print('\nERROR')
Basically I made, a command which should tell if a link is safe or not, I did it using google's verification report site, but.. the problem is I only reformatted the link so the bot sens it in an embed and you access it from there.
My question is, now that you understood what I need, is there some way in which I could directly let the bot output the message from the website that indicates if the site is malicious/safe ??
Please help me.
I provided an image as well with the message I want to get from the site.
You might want to try scraping the site with bs4, or just look for the string "No unsafe content found". However, it looks like google populates the field based on a request.
Your best bet would be to use transparencyreport.google.com/transparencyreport/api/v3/safebrowsing/status?site=SITE_HERE. It returns a JSON response, but I don't understand it, so play around and figure out what the keys mean
Im am right now creating an info command for my discord bot and want to make a footer in an embed with the developers/my name and avatar.
But now if I add my name and avatar url to the field then when I change name or avatar the informations in the footer will still stay the same.
Is there something I can use, to get my own avatr url and name just like I get the ctx.author.avatar_url and ctx.author?
Or is threre something like bot.owner?
This is my code:
user_me = ?
em = discord.Embed()
em.set_footer(icon_url=user_me.avatar_url, text=user_me)
You need to use your id, and from that you can create a user object.
user = await bot.fetch_user(<your_id>)
em = discord.Embed()
em.set_footer(icon_url=user.avatar_url, text=user.name)
I'm doing a bot, in which I want the user to start the bot to verify that the user of the telegram channel. I'm programming in python with the api telebot.
With this I get the user.id of the user:
idUser = str (message.from_user.id)
With this I have managed to obtain the number of users, but not the ids to do the verification:
members = tb.get_chat_members_count ("# ChannelName")
according to the documentation all api methods are callable but modified to python standards so it would become
memberobject = tb.get_chat_member(channel,userid)