How To Make A Auto Reply Event For Dm's
I have this Code but I cant get it run with the Command so I can turn it on and off: auto_dm = 'off' @bot.command() async def autoreply(ctx, mode: str): ''' On or Off ''' awai
Solution 1:
It's never on
cause you're not editing the auto_dm
variable, you need to use the global
keyword in the autoreply
command in order to change it
@bot.command()asyncdefautoreply(ctx, mode: str):
global auto_dm
await ctx.message.delete()
auto_dm = mode
Also there are a couple of things wrong with your code
- The
Events
cog doesn't have an__init__
method - You don't need a while loop in the
on_message
event, there's no purpose for that - You should use booleans instead of
on/off
- You don't need the
else: pass
, simply don't put it
Here's the cog fixed
classEvents(commands.Cog):
def__init__(self, bot):
self.bot = bot
@commands.Cog.listener()asyncdefon_message(self, message):
if message.author == self.bot.user:
return# Exiting if the author of the message is ourselfif auto_dm == 'on': # I'd really recommend you using True/Falseifisinstance(message.channel, discord.DMChannel):
automsg = config.get("automessage")
await message.channel.send(automsg)
time = datetime.datetime.now().strftime("%H:%M")
print(f"{time} | {Fore.LIGHTCYAN_EX}[Event]{Fore.RESET} | Auto Reply Message send to {message.author}")
Post a Comment for "How To Make A Auto Reply Event For Dm's"