Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Python discord.py (discord bot)

D

Deleted member 1442

Guest
Hello, I wanted to make a public discord bot when I started discord. I have the bot setup in my server, but I want to expand. I created another python file for the public bot, because I wanted there to be commands for my server. I want to save all the data for one server put it on a JSON file and use that for each server.
I'm not familiar with discord.py. Here's what data I need to save for each server:
Prefix.
Server id & server name (I already can get the server id with ctx.guild.id, but I don't know how to get the name of it and store it.)
Permissions for roles.
Role IDs and name for auto-role.
Channel id and name for !announcement.
I want this data to work like im in blank server and their prefix for my bot is '$' and cool server and their prefix for my bot is '>' and both would still work with different prefixs & data in different servers.
Here's my code already for the PUBLIC BOT.
Python:
Import discord.py
import discord
from discord.ext import commands
from db import *

#Client
client = commands.Bot(command_prefix='!') #default
TOKEN = 'my token'

#startup
@client.event
async def on_ready():
    await client.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name="discord.gg/mydiscordserver | !"))

@client.event
async def on_member_join():
    '''Some Code'''

class all_commands:
    @client.command(brief='Will send a message called "Pong!', description='Will send a message called "Pong!')
    async def ping(ctx):
        await ctx.send(f'Pong! {ctx.message.author.mention}')

    @client.command(brief='Will say what every after the command.', description='This command will print in the command line.')
    @commands.has_any_role("Administrator")
    async def say(ctx, *, message):
        #await ctx.message.delete()
        await ctx.send(f'{message}' .format(message))

    @client.command(brief='Will change the prefix of the bot, until restarted. (Developer Only)', description='Will change the prefix of the bot, until restarted.')
    @commands.has_any_role("Administrator")
    async def prefix(ctx, prefix):
        client.command_prefix = prefix
        await ctx.send(f"Prefix changed to ``{prefix}``")

    @client.command(brief='Will clear chat.', description='Will clear chat.')
    @commands.has_any_role("Administrator")
    async def clear(ctx, amount = 1000):
        await ctx.message.delete()
        await ctx.channel.purge(limit = amount)

#run
client.run(TOKEN)
 

New Threads

Buy us a coffee!

Back
Top Bottom