Yusuf2020
Yusuf2020

Reputation: 23

Discord sends message more than expected

import requests
from bs4 import BeautifulSoup
from random import choice
import re, json
import discord
Bot = discord.Client()

def names():
    asd = []
    n = open("1", "wb")
    url = 'aurl.com'
    r = requests.get(url).text
    a = json.loads(r)
    for i in a.items():
        asd.append(i[1]["baslik"])
    return asd
@Bot.event
async def on_ready():
    print(1)
    list = names()
    channel = Bot.get_channel(825744124485173298)
    for i in list:
        await channel.send(i)
Bot.run(key)

I want this bot to get dicts from 'aurl.com' site and send it. But following script send same dict more than one time. Where am i making mistake ?

Upvotes: 0

Views: 36

Answers (1)

Lucas
Lucas

Reputation: 345

The on_ready event has explicit documentation that states:

This function is not guaranteed to be the first event called. Likewise, this function is not guaranteed to only be called once. This library implements reconnection logic and thus will end up calling this event whenever a RESUME request fails.

Upvotes: 1

Related Questions