Skip to content

Commit 75ee29e

Browse files
committed
Update bot setup test script
1 parent 7ce5bcb commit 75ee29e

1 file changed

Lines changed: 14 additions & 11 deletions

File tree

docs/discord-server-bot-setup.md

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,39 +102,42 @@ Copy your new token and store it somewhere safe.
102102
![Bot: Copy Token](img/bot-copy-token.png)
103103

104104
To 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+
# ///
108111
import asyncio
109112

110113
import discord
111114
from discord.ext import commands
112115

113-
BOT_TOKEN = "..."
114-
115116

116117
class 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

121124
class 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

136137
if __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

140143
In Discord, go to your server and write the message `$ping` in a text channel.

0 commit comments

Comments
 (0)