Answer the question
In order to leave comments, you need to log in
How to make a bot on Discord that would take information from the site and send it to the discord chat?
Hello, I want to create a news-type bot for my server (so that it takes information from the site and transfers it all to the discord chat, please help) because I have little knowledge of python.
Answer the question
In order to leave comments, you need to log in
Your example is well implemented
from urllib.request import urlopen
import random
import discord
from discord.ext import commands
import json
BotToken = ''
bot = commands.Bot(command_prefix='')
@bot.command(pass_context=True)
async def get_post(ctx):
html_doc = urlopen(
"http://api.vk.com/method/wall.get?v=5.3&domain=!!!ГРУППА!!!&count=20&access_token=").read()
JSON = json.loads(html_doc)
response = JSON['response']
items = response['items']
i = random.randint(0, len(items) - 1)
embed = discord.Embed(
title='Открыть в ВК',
url="https://vk.com/!!!ГРУППА!!!?w=wall" + str(items[i]['from_id']) + '_' + str(items[i]['id']),
description=items[i]['text']
)
try:
attachments = items[i]['attachments'][0]
print(attachments)
if attachments['type'] == 'photo':
try:
photos = attachments['photo']
photo = photos['photo_604']
except:
photo = str(attachments)[str(attachments).find('http'):str(attachments).find('.jpg') + 4]
print(photo)
embed.set_image(url=photo)
except:
print()
await ctx.send(embed=embed)
bot.run(BotToken)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question