简体   繁体   English

如何使用 discord.py 简单地发送消息

[英]How to simply send a message using discord.py

Okay i have a very simple question but i couldnt find out how to solve it by any chance.好的,我有一个非常简单的问题,但我不知道如何解决它。 I have a script that fetches some numbers out of the steam website, then compares them.我有一个脚本可以从 Steam 网站中获取一些数字,然后进行比较。 i want to use discord.py to send me that results on discord.我想使用 discord.py 将 discord 的结果发送给我。 i already have the bot on discord, but i coulndt figure out how to just send a message and not react to a message sent by a user or anything.我已经在 discord 上安装了机器人,但我无法弄清楚如何只发送消息而不对用户发送的消息或任何东西做出反应。 This is my code:这是我的代码:

Float = float(Float[8:])
if Float <= 0.01:
    element2 = driver.find_element_by_xpath('/html/body/div[1]/div[7]/div[2]/div[2]/div[4]/div[1]/div[3]/div[4]/div[4]/div[2]/div[2]/div[2]/span/span[1]')
    Price = element2.text
    print("Snipe found: \n"
          "Mag-7 Carbon Fiber Factory New with Float:\n"
          , Float, '\n', Price)

i also have some selenium in it, but that is not a problem.我也有一些 selenium ,但这不是问题。 the variable "Float" is also defined before.变量“Float”也是之前定义的。 i simply want to send the stuff that is in the print function as a message to a discord server.我只是想将print中的内容 function 作为消息发送到 discord 服务器。
is this possible by any chance?这有可能吗?
Thanks for the help谢谢您的帮助

Just make it a command and use ctx.send() .只需将其设为命令并使用ctx.send() Since you don't know how to send a message on discord.py, I'm assuming that you are very new to it.由于您不知道如何在 discord.py 上发送消息,我假设您对它很陌生。

import ...
from discord.ext import commands
import discord

bot = commands.Bot(command_prefix='!')

@bot.command()
async def steamfetch(ctx):
    Float = float(Float[8:])
    if Float <= 0.01:
        element2 = driver.find_element_by_xpath('/html/body/div[1]/div[7]/div[2]/div[2]/div[4]/div[1]/div[3]/div[4]/div[4]/div[2]/div[2]/div[2]/span/span[1]')
        Price = element2.text
        await ctx.send(f"Snipe found:\nMag-7 Carbon Fiber Factory New with Float:\n{Float}\n{Price}')

You should really look at the discord.py docs or other discord.py tutorials for this because sending a message are in MANY of the discord.py tutorials.您真的应该查看discord.py 文档或其他 discord.py 教程,因为发送消息在许多 discord.py教程中。 I don't know if you did but please try doing your own research before asking a question here.我不知道您是否这样做,但请在此处提问之前尝试自己进行研究。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM