I am new to creating discord bots and have seen answers to similar questions but none that solved my issue.
For context: I want the bot to constantly scrape a website, updating a list of objects, and when a new object is detected, it would then send a message to any discord channel its running in with the information of the new object.
Here is a code snippet:
for i in range(len(masterList)):
if masterList[i].new == True:
# client.dispatch("custom_event", ctx, masterList[i]) ?
@client.event
async def on_ready():
print("The bot is now ready for use!")
print("-----------------------------")
@client.event
async def on_custom_event(ctx, server):
await ctx.send(server)
The masterList is a list of objects called server:
class server:
def __init__(self, servername, map, gamemode, playercount, new):
self.servername = servername
self.map = map
self.gamemode = gamemode
self.playercount = playercount
self.new = new
def __repr__(self):
return "Server:% s Map:% s Gamemode:% s Playercount:% s" % (self.servername, self.map, self.gamemode, self.playercount)
def __eq__(self, other):
return self.servername == other.servername
From my understanding the context(ctx) is used on command triggers to see where the command was run from so that the bot can respond to the appropriate guild/channel. So how do I send messages to guilds without ctx? How do I even call this custom event in the first place? I’ve seen posts using the bot.dispatch which I have commented out because I could not figure out how to properly implement this or find any documentation on it.
Thank you!