Home > Back-end >  D.py/rewrite - Confessions System
D.py/rewrite - Confessions System

Time:10-08

I made a confessions system but there’s some things that are wrong with it. How would I make it so when users want to type, they don’t have to put in *confess and they can just type whatever they want without needing to use a command? And how do I make a mod logs channel to log the deleted confessions with the author name, etc.?

import discord
from discord.ext import commands


class Confess(commands.Cog):
    def __init__(self, client: discord.ext.commands.Bot):
        self.client = client

    @commands.command()
    async def confess(self, ctx: commands.Context, *, message: str):
        channel = self.client.get_channel(806649868314869760)
        await ctx.message.delete()
        embed = discord.Embed(title="Success", description=f"I've received your confession and sent it to the <#806649874379964487> channel!")
        embed.set_footer(text="Confessions")
        await ctx.send(embed=embed, delete_after=10)
        channel = self.client.get_channel(806649874379964487)
        embed = discord.Embed(title="Confession", description=f"{message}")
        embed.set_footer(text="All confessions are anonymous.")
        await channel.send(embed=embed)



def setup(client):
    client.add_cog(Confess(client))

CodePudding user response:

For the first question
If you want to use a "command" without actually using a command you could make an on_message event, check the id of the channel (like a confessions channel) and if it matches then do the thing

Example:

@commands.Cog.listener()
async def on_message(message):
    if message.channel.id == some_channel_id_here:
        channel = self.client.get_channel(806649868314869760)
        await message.delete()
        embed = discord.Embed(title="Success", description=f"I've received your confession and sent it to the <#806649874379964487> channel!")
        embed.set_footer(text="Confessions")
        await message.channel.send(embed=embed, delete_after=10)
        channel = self.client.get_channel(806649874379964487)
        embed = discord.Embed(title="Confession", description=f"{message}")
        embed.set_footer(text="All confessions are anonymous.")
        await channel.send(embed=embed)

For the second question
You can use get_channel again to get the log channel and post in there. (If you mean't on how to check if someone deleted a message/confession, use on_message_delete)

Example:

@commands.command()
    async def confess(self, ctx: commands.Context, *, message: str):
        channel = self.client.get_channel(806649868314869760)
        log_channel = self.client.get_channel(log_channel_id)
        await ctx.message.delete()
        embed = discord.Embed(title="Success", description=f"I've received your confession and sent it to the <#806649874379964487> channel!")
        embed.set_footer(text="Confessions")
        await ctx.send(embed=embed, delete_after=10)
        channel = self.client.get_channel(806649874379964487)
        embed = discord.Embed(title="Confession", description=f"{message}")
        embed.set_footer(text="All confessions are anonymous.")
        await channel.send(embed=embed)
        await logchannel.send("User confessed something!")
  • Related