Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
381 views
in Technique[技术] by (71.8m points)

Posting to discord webhook from python

REPOST Due To Basically No One Viewing

I am currently working on a python program and im looking for the users computer data to be sent to a discord webhook, the idea is to be that the users Computer's hardware info would be sent to the webhook when they open the program it would also send their public IP address, After i have the program done it will be converted to an exe using pyinstaller so people can open it but they wont be able to edit it. Please see the code i have tried bellow and if anyone can edit/change the code so that it would work and would successfully send the user data over to the webhook that would be a massive help! Thanks

I took the discord webhook text from https://pypi.org/project/discord-webhook/

#getting system info
ip = get('https://api.ipify.org').text
print('Ip address=: {}'.format(ip))
print("="*40, "System Information", "="*40)
uname = platform.uname()
print(f"System: {uname.system}")
print(f"Node Name: {uname.node}")
print(f"Release: {uname.release}")
print(f"Version: {uname.version}")
print(f"Machine: {uname.machine}")
print(f"Processor: {uname.processor}")
#Discord webhook stuff
from discord_webhook import DiscordWebhook, DiscordEmbed

webhook = DiscordWebhook(url="your webhook url", username="New Webhook Username")

embed = DiscordEmbed(
    title="Embed Title", description="Your Embed Description", color=242424
)
embed.set_author(
    name="Author Name",
    url="https://github.com/lovvskillz",
    icon_url="https://avatars0.githubusercontent.com/u/14542790",
)
embed.set_footer(text="Embed Footer Text")
embed.set_timestamp()
# Set `inline=False` for the embed field to occupy the whole line
embed.add_embed_field(name="System", value="Lorem ipsum", inline=False)
embed.add_embed_field(name="Name", value="dolor sit", inline=False)
embed.add_embed_field(name="Version", value="amet consetetur")
embed.add_embed_field(name="Processor", value="sadipscing elitr")

webhook.add_embed(embed)
response = webhook.execute()
The system info bit works fine on its own it prints out all the info that you can see, the tricky part is the Discord section as im stuck on how to send the system data over to the discord webhook rather than it just printing out into the console.

Any help would be great

Thanks, Oliver

(I have removed any info such as the discord webhook i was using to stop people from logging into it)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can just remove (or comment putting a # before) the print line to stop your script from printing the information on the console.

To post the information in your webhook, you can set the values that are in the print statement in the value field of the webhook. Example:

 embed.add_embed_field(name="System", value=f"{uname.system}", inline=False)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...