@@ -102,39 +102,42 @@ Copy your new token and store it somewhere safe.
102102![ Bot: Copy Token] ( img/bot-copy-token.png )
103103
104104To confirm the installation, install the Python package [ discord.py] ( https://pypi.org/project/discord.py/ )
105- (e.g. with ` pip install discord.py ` ), and run the following script (add your bot token at ` BOT_TOKEN = "..." ` ) :
105+ (e.g. with ` pip install discord.py ` ), run the following script, and enter your bot token when prompted :
106106
107107``` python
108+ # /// script
109+ # dependencies = ["discord-py"]
110+ # ///
108111import asyncio
109112
110113import discord
111114from discord.ext import commands
112115
113- BOT_TOKEN = " ..."
114-
115116
116117class Bot (commands .Bot ):
117118 async def on_ready (self ):
118- print (" ready" , self .user.name, self .user.id)
119+ print (f " Bot is running as user { self .user.name!r } . " )
120+ print (" Post $ping in any channel on your server to test the bot." )
121+ print (" Press Ctrl+C to stop the bot." )
119122
120123
121124class Ping (commands .Cog ):
122- @commands.hybrid_command (name = " ping" )
125+ @commands.command (name = " ping" )
123126 async def ping (self , context ):
124127 await context.send(" Pong!" )
125128
126129
127- async def main ():
128- prefix = commands.when_mentioned_or(" $" )
129-
130+ async def main (token : str ) -> None :
130131 intents = discord.Intents(messages = True , message_content = True )
131- async with Bot(command_prefix = prefix , intents = intents) as bot:
132+ async with Bot(command_prefix = " $ " , intents = intents) as bot:
132133 await bot.add_cog(Ping())
133- await bot.start(BOT_TOKEN )
134+ await bot.start(token )
134135
135136
136137if __name__ == " __main__" :
137- asyncio.run(main())
138+ bot_token = input (" Please enter your bot token: " ).strip()
139+ print (" Bot is starting, please wait..." )
140+ asyncio.run(main(bot_token))
138141```
139142
140143In Discord, go to your server and write the message ` $ping ` in a text channel.
0 commit comments