Language: Python
Web
Hikari was created to provide a highly performant and robust framework for building Discord bots in Python. It emphasizes type safety, concurrency, and modern Python async features. Developers use Hikari for building scalable, reliable, and feature-rich Discord bots.
Hikari is a modern, fast, and type-safe Python library for building Discord bots. It is designed for high performance, asynchronous execution, and full support of Discord API features.
pip install hikariconda install -c conda-forge hikariHikari allows you to create bots that handle events, send messages, manage channels, and interact with Discord servers. It supports asynchronous programming, event-driven architecture, and integration with other libraries for commands, interactions, and more.
import hikari
bot = hikari.GatewayBot(token='YOUR_BOT_TOKEN')
@bot.listen()
async def on_ready(event: hikari.ShardReadyEvent):
print('Bot is ready!')
bot.run()Creates a basic Hikari bot that prints a message when the bot is ready.
await bot.rest.create_message(channel=CHANNEL_ID, content='Hello from Hikari!')Sends a message to a specific channel using the bot's REST client.
@bot.listen(hikari.MessageCreateEvent)
async def on_message(event: hikari.MessageCreateEvent):
if event.content == '!ping':
await event.message.respond('Pong!')Listens to new messages and responds to a '!ping' command with 'Pong!'.
import lightbulb
plugin = lightbulb.Plugin('example')
@plugin.command()
@lightbulb.command('hello', 'Say hello')
@lightbulb.implements(lightbulb.SlashCommand)
async def hello(ctx):
await ctx.respond('Hello!')
bot.add_plugin(plugin)Demonstrates creating a slash command using the Lightbulb extension for Hikari.
@bot.listen(hikari.ReactionAddEvent)
async def on_reaction(event: hikari.ReactionAddEvent):
print(f'{event.user_id} reacted with {event.emoji}')Logs whenever a user reacts to a message.
await bot.update_presence(activity=hikari.Activity(name='with Hikari', type=hikari.ActivityType.PLAYING))Updates the bot's presence to show a custom activity message.
member = await bot.rest.fetch_member(guild=GUILD_ID, user=USER_ID)
print(member.username)Fetches information about a specific guild member.
Use async/await for all I/O operations to maintain performance.
Leverage Lightbulb for command management and modularity.
Handle exceptions in events to prevent bot crashes.
Use environment variables for bot tokens and sensitive information.
Monitor rate limits and respect Discord API constraints.