def build_gateway_bot(*, config: config_.FullConfig | None = None) -> tuple[hikari.impl.GatewayBot, tanjun.Client]: """Build a gateway bot with a bound Reinhard client. Other Parameters ---------------- config: reinhard.config.FullConfig The configuration to use. Returns ------- tuple[hikari.impl.GatewayBot, tanjun.Client] The gateway bot and Reinhard client. """ if config is None: config = config_.FullConfig.from_env() bot = hikari.GatewayBot( config.tokens.bot, logs=config.log_level, intents=config.intents, cache_settings=hikari.CacheSettings(components=config.cache), # rest_url="https://canary.discord.com/api/v8" # rest_url="https://staging.discord.co/api/v8" ) return bot, build_from_gateway_bot(bot, config=config)
from hikari.presences import Activity, ActivityType TOKEN = cred['DISCORD_TOKEN'] last_sriracha_embed = {} last_sriracha_lc = {} bots = { "sriracha": 607661949194469376, "ohsheet": 640402425395675178, "lc": 661826254215053324 } logger = logging.getLogger("Mortal Log") ANTIBUG = logging.INFO - 5 logging.addLevelName(ANTIBUG, "INDIAN_CUSTOMER_SERVICE") bot = hikari.GatewayBot(token=TOKEN, logs="INDIAN_CUSTOMER_SERVICE") prefixes = ("lc", "qc", "st", "en", "jp") def mortallog(log_message: str): logger.log(ANTIBUG, log_message) def clean_args(cmd: str, args): try: return args.group(cmd).lower() except AttributeError: return None def is_sriracha_bot(message_event: hikari.GuildMessageCreateEvent) -> bool:
# -*- coding: utf-8 -*- # Hikari Examples - A collection of examples for Hikari. # # To the extent possible under law, the author(s) have dedicated all copyright # and related and neighboring rights to this software to the public domain worldwide. # This software is distributed without any warranty. # # You should have received a copy of the CC0 Public Domain Dedication along with this software. # If not, see <https://creativecommons.org/publicdomain/zero/1.0/>. """A simple bot with only a `!ping` command.""" import os import hikari bot = hikari.GatewayBot(token=os.environ["BOT_TOKEN"]) @bot.listen() async def on_message(event: hikari.MessageCreateEvent) -> None: """Listen for messages being created.""" if not event.is_human: # Do not respond to bots or webhooks! return if event.content == "!ping": await event.message.respond( f"Pong! {bot.heartbeat_latency * 1_000:.0f}ms") bot.run()
# all copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. import hikari import topgg from .callbacks import autopost, webhook app = hikari.GatewayBot("TOKEN") webhook_manager = topgg.WebhookManager().set_data(app).endpoint( webhook.endpoint) dblclient = topgg.DBLClient("TOPGG_TOKEN").set_data(app) autoposter: topgg.AutoPoster = (dblclient.autopost().on_success( autopost.on_autopost_success).on_error(autopost.on_autopost_error).stats( autopost.stats)) @app.listen() async def on_started(event: hikari.StartedEvent): me: hikari.OwnUser = event.app.get_me() assert me is not None dblclient.default_bot_id = me.id # since StartedEvent is a lifetime event
import hikari bot = hikari.GatewayBot( token='OTU0MzkxNjAyNTM1NzQ3NjU0.YjSccQ.X3AHEct62oWUOm1XPmVkYSG7cSg') @bot.listen(hikari.GuildMessageCreateEvent) async def print_message(event): print(event.content) @bot.listen(hikari.StartedEvent) async def bot_started(event): print('Bot has started!') bot.run()
import hikari from antispam import AntiSpamHandler from antispam.enums import Library from examples.jsonLoader import read_json file = read_json("token") bot = hikari.GatewayBot(token=file["token"], ) handler = AntiSpamHandler(bot, library=Library.HIKARI) @bot.listen() async def ping(event: hikari.GuildMessageCreateEvent) -> None: if event.is_bot or not event.content: return await handler.propagate(event.message) bot.run()
async def track_exception(self, lavalink: lavasnek_rs.Lavalink, event: lavasnek_rs.TrackException) -> None: """Handles track exception events.""" print(f"Track exception event happened on guild: {event.guild_id}") # If a track was unable to be played, skip it skip = await lavalink.skip(event.guild_id) node = await lavalink.get_guild_node(event.guild_id) if skip and node: if not node.queue and not node.now_playing: await lavalink.stop(event.guild_id) bot = hikari.GatewayBot(DISCORD_TOKEN) client = tanjun.Client.from_gateway_bot(bot, declare_global_commands=True, mention_prefix=True) @client.with_listener(hikari.ShardReadyEvent) async def on_shard_ready( event: hikari.ShardReadyEvent, client_: tanjun.Client = tanjun.injected(type=tanjun.Client), ) -> None: """Event that triggers when the hikari gateway is ready.""" builder = ( lavasnek_rs.LavalinkBuilder(event.my_user.id, DISCORD_TOKEN).set_host( LAVALINK_HOST).set_password(LAVALINK_PASSWORD).set_port(