-
Автор темы
- #1
This code creates a Discord bot using the discord.Client class. When the bot receives a message that starts with "!level", it will increment the level of the user who sent the message by 1. The levels of each user are stored in a dictionary, where the keys are the user IDs and the values are the levels. The bot then sends a message to the channel with the updated level information.
Code::
import discord
client = discord.Client()
levels = {}
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith("!level"):
user_id = message.author.id
if user_id in levels:
levels[user_id] += 1
else:
levels[user_id] = 1
await message.channel.send(f"{message.author.mention} is now level {levels[user_id]}")
client.run(токен)