Learn Before
Initializing bot variables
Before we can run the bot, we need to load our environmental variables and configure our bot's commands. If using dotenv, run the follow line of code to load up the variables you have stored in your .env file:
load_dotenv()
To actually access those variables you need to access them from within your operating system which can be done as follows:
TOKEN = os.environ["TOKEN"] GUILD_ID = [int(os.environ["GUILD_ID"])]
Environmental variables are stored as strings and we need GUILD_ID to be an int for later so we convert it at this stage.
Next up we will define what our bot is called in code. Common names are "client" or "bot" and in this case we will use "client".
client = discord.Client(intents=discord.Intents.default()) slash = SlashCommand(client, sync_commands=True)
This will initialize the bot as "client" and specifies what the bot intends to do, which in this case is just the default as we won't be needing additional actions given by privileged intents (read more in the linked reference node). slash stores our slash commands as a variable which we will use to define behaviors for command calls.
0
1
Tags
Python Programming Language
Data Science