innerrest.blogg.se

Icon bot discord
Icon bot discord









icon bot discord

But in this case, it allows your Discord bot to send a message. The ctx instance is a context, and it has many functions. This is essential, as it's the only way for the module to communicate with Discord. Looking closely, you'll see that we've used the async await method to serve the function. Then go to Discord and send "Hi" to see the magic unfold. Now run the Python script in your terminal. Note that custom commands are Python functions: import discordīot = commands.Bot(command_prefix= " def Hi (ctx):Īwait ctx.send( "Hi, welcome to our server ") Using the decorator, let's make a custom command, Hi, and provide a reply text for the Discord bot when it sees it. So you don't need one while instructing the Discord bot. Characters like the dollar sign ($), exclamation (!), ampersand (&), and more are common prefixes that precede bot commands.īut we've blanked the prefix in our case. And the command_prefix in the parenthesis lets you specify a character that precedes it. The bot variable invokes custom commands from the command class. #Read your bot token from the txt file in your project root: # Initialize the bot instance and use a blank prefix: Here, you'll program your Discord bot to reply with a custom message when you send a text in a channel.īut first, type the following code at the top of your script to initialize your Discord bot: import discord

#Icon bot discord install

With the virtual environment active, run the following command in your terminal to install these packages: pip install -U discord.











Icon bot discord