0

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. i want to use discord.py to send me that results on 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. 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. the variable "Float" is also defined before. i simply want to send the stuff that is in the print function as a message to a discord server.
is this possible by any chance?
Thanks for the help

Timeler
  • 377
  • 1
  • 11
  • By any chance, [This questions](https://stackoverflow.com/questions/54081106/sending-a-message-to-a-specific-user-specified-in-the-message-discord-py)'s answer may help you. – Kaan Berke UĞURLAR Dec 20 '20 at 20:38
  • Well but here i also need to write !Help or something, and i want to leave that step out, like the script just posts it without a request – Timeler Dec 20 '20 at 20:54

1 Answers1

2

Just make it a command and use 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.

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. I don't know if you did but please try doing your own research before asking a question here.

Makyen
  • 31,849
  • 12
  • 86
  • 121
nonimportant
  • 406
  • 4
  • 15
  • Thanks I will try that out, and i looked into docs and guides etc, but nothing really worked. I also wasnt sure if i could add other stuff to that @bot.command() part, other than discord.py related things – Timeler Dec 20 '20 at 21:09
  • @Timeler huh wdym? what was the stuff you tried out? many of the guides say to use `ctx.send()` or `ctx.channel.send()` – nonimportant Dec 20 '20 at 21:23
  • Yeah but like i didnt know that i can put that other if float <= into it etc, and it also didnt really work with the other stuff i tried. I also didnt know that i can def the steamfetch with whatever i want – Timeler Dec 21 '20 at 06:44
  • btw that solution didnt work, i tried it out and nothing happend with that exact code, possibly i have the bot.run() on the wrong place idk – Timeler Dec 21 '20 at 07:24
  • @Timeler Something must be wrong with ur code bc `await ctx.send()` does send a message without fail. Did an error come up? if so which one? Do other commands work as well? – nonimportant Dec 21 '20 at 22:29