I made a bot for managing the bot of Pricone, so I noticed that. https://github.com/izmktr/yukarisan
on_ready is called when connecting to discord Also, it seems to be disconnected from discord irregularly, It will also be called when you reconnect automatically.
Here, it seems good to combine the information that you have internally with the data of discord.py.
import discord
from discord.ext import tasks
from typing import List, Dict, Optional
#guild_Linking id with internal class
guildhash: Optional[Dict[int, GuildData]] = None
@client.event
def on_ready():
global guildhash
if guildhash is None:
#Load processing
guildhash = {}
for g in client.guilds:
gdata = guildhash.get(g.id)
if gdata is None:
gdata = GuildData()
guildhash[g.id] = gdata
gdata.guild = g
Occurs when adding / removing reactions, It is on_reaction_add, on_reaction_remove, but it may not be called. Generally, a message about 15 minutes after it is posted may not respond. (I think it depends on the activity of the server) Probably, I feel that on_message_delete does not fly when this happens.
Since max_messages is 1000, I thought it could be avoided by increasing it, I couldn't avoid it even if I put 100000 like this. (Looking for knowledge in this area)
#has no meaning?
client = discord.Client(max_messages = 100000)
You can use on_raw_reaction_add and on_raw_reaction_remove to make sure you fly. Save the message information with on_message and use on_raw_reaction_ ~ It would be nice to resolve the process.
In addition, it is called in the order of on_raw_reaction_add → on_reaction_add. If on_reaction_add flies here, I thought it would be on_raw_reaction_add if it didn't fly, This process seems to be troublesome because the order is reversed.
You can have a private chat with the bot by sending a message to the bot. If you use development commands, use private chat, You can work without seeing the logs around you.
@client.event
async def on_message(message):
#Ignore if the message sender is a bot
if message.author.bot:
return
#Normal message
if message.channel.type == discord.ChannelType.text:
return
# 1:1 message
if message.channel.type == discord.ChannelType.private:
return
The problem is that the type of message is different from that of a normal message So there are class variables and class functions that are missing.
Also, since there is no guild in the private message, You must specify the guild in your private message.
If you design it to absorb this difference and create processing for various commands It is a reflection that it would have been convenient.
Recommended Posts