Skip to content

Repository files navigation

Ourted: A Discord bot in PHP

The Ourted library provides a running bot process written in PHP.

Installation

composer require ourted/ourted

Edit .env and configure bot token

Examples

More documents in example/Ourted.php

Without Event Listener

<?phprequire_once__DIR__ . '/vendor/autoload.php';
useDotenv\Dotenv;
useOurted\Bot;
class Ourted extends Bot
{
public$token;
publicfunction__construct()
{
$dotenv = Dotenv::createImmutable(__DIR__);
$dotenv->load();
$this->token = $_ENV['BOT_TOKEN'];
parent::__construct($this->token, '!'); /* 1: Bot Token, 2: Bot Prefix */$this->setBot();
}
publicfunctionsetBot()
{
echo"Hello World\n";
$this->run();
}
}
newOurted();
?>

Result Log:

Example


With Event Listener

<?phprequire_once__DIR__ . '/vendor/autoload.php';
useDotenv\Dotenv;
useOurted\Bot;
class Ourted extends Bot
{
public$token;
publicfunction__construct()
{
$dotenv = Dotenv::createImmutable(__DIR__);
$dotenv->load();
$this->token = $_ENV['BOT_TOKEN'];
parent::__construct($this->token, "!");
$this->setBot();
}
publicfunctionsetBot()
{
// Ready Event Listener$this->addListeners(
"EventListener"
);
echo"Hello World\n";
$this->run();
}
}
class EventListener extends \Ourted\Model\EventListener\EventListener
{
/* GUILDS (1<<0) *//** * @param mixed $json * @param Bot $bot */publicfunctiononGuildCreate($json, $bot)
{
}
/** * @param mixed $json * @param Bot $bot */publicfunctiononGuildDelete($json, $bot)
{
}
/** * @param mixed $json * @param Bot $bot */publicfunctiononGuildUpdate($json, $bot)
{
}
/** * @param mixed $json * @param Bot $bot */publicfunctiononGuildRoleCreate($json, $bot)
{
}
/** * @param mixed $json * @param Bot $bot */publicfunctiononGuildRoleUpdate($json, $bot)
{
}
/** * @param mixed $json * @param Bot $bot */publicfunctiononGuildRoleDelete($json, $bot)
{
}
/** * @param mixed $json * @param Bot $bot */publicfunctiononChannelCreate($json, $bot)
{
}
/** * @param mixed $json * @param Bot $bot */publicfunctiononChannelUpdate($json, $bot)
{
}
/** * @param mixed $json * @param Bot $bot */publicfunctiononChannelDelete($json, $bot)
{
}
/** * @param mixed $json * @param Bot $bot */publicfunctiononChannelPinsUpdate($json, $bot)
{
}
/* GUILD_MEMBERS (1<<0) *//** * @param mixed $json * @param Bot $bot */publicfunctiononGuildMemberAdd($json, $bot)
{
}
/** * @param mixed $json * @param Bot $bot */publicfunctiononGuildMemberUpdate($json, $bot)
{
}
/** * @param mixed $json * @param Bot $bot */publicfunctiononGuildMemberDelete($json, $bot)
{
}
/* GUILD_BANS (1<<2) *//** * @param mixed $json * @param Bot $bot */publicfunctiononGuildBanAdd($json, $bot)
{
}
/** * @param mixed $json * @param Bot $bot */publicfunctiononGuildBanRemove($json, $bot)
{
}
/* GUILD_EMOJIS (1<<3) *//** * @param mixed $json * @param Bot $bot */publicfunctiononGuildEmojisUpdate($json, $bot)
{
}
/* GUILD_INTEGRATIONS (1<<3) *//** * @param mixed $json * @param Bot $bot */publicfunctiononGuildIntegrationsUpdate($json, $bot)
{
}
/* GUILD_WEBHOOKS (1 << 5) *//** * @param mixed $json * @param Bot $bot */publicfunctiononWebhooksUpdate($json, $bot)
{
}
/* GUILD_INVITES (1 << 6) *//** * @param mixed $json * @param Bot $bot */publicfunctiononInviteCreate($json, $bot)
{
}
/** * @param mixed $json * @param Bot $bot */publicfunctiononInviteDelete($json, $bot)
{
} /* GUILD_VOICE_STATES (1 << 7) *//** * @param mixed $json * @param Bot $bot */publicfunctiononVoiceStateUpdate($json, $bot)
{
}
/* GUILD_PRESENCES (1 << 8) *//** * @param mixed $json * @param Bot $bot */publicfunctiononPresenceUpdate($json, $bot)
{
}
/* GUILD_MESSAGES (1 << 9) *//** * @param mixed $json * @param Bot $bot */publicfunctiononMessageCreate($json, $bot)
{
}
/** * @param mixed $json * @param Bot $bot */publicfunctiononMessageUpdate($json, $bot)
{
}
/** * @param mixed $json * @param Bot $bot */publicfunctiononMessageDelete($json, $bot)
{
}
/** * @param mixed $json * @param Bot $bot */publicfunctiononMessageDeleteBulk($json, $bot)
{
}
/* -GUILD_MESSAGE_REACTIONS (1 << 10) *//** * @param mixed $json * @param Bot $bot */publicfunctiononMessageReactionAdd($json, $bot)
{
}
/** * @param mixed $json * @param Bot $bot */publicfunctiononMessageReactionRemove($json, $bot)
{
}
/** * @param mixed $json * @param Bot $bot */publicfunctiononMessageReactionRemoveAll($json, $bot)
{
}
/** * @param mixed $json * @param Bot $bot */publicfunctiononMessageReactionRemoveEmoji($json, $bot)
{
}
/* GUILD_MESSAGE_TYPING (1 << 11) *//** * @param mixed $json * @param Bot $bot */publicfunctiononTypingStart($json, $bot)
{
} }
newOurted();
?>

Result:

Example With Event Listener

Command

<?phprequire_once__DIR__ . '/vendor/autoload.php';
useDotenv\Dotenv;
useOurted\Bot;
class Ourted extends Bot
{
public$token;
publicfunction__construct()
{
$dotenv = Dotenv::createImmutable(__DIR__);
$dotenv->load();
$this->token = $_ENV['BOT_TOKEN'];
parent::__construct($this->token, '!');
$this->setBot();
}
publicfunctionsetBot()
{
$this->addCommand("test_command", function ($bot, $command_name){
newTestCommand($bot, $command_name);
});
$this->run();
}
}
class TestCommand extends Command{
publicfunctionexecute($message, $bot, $channel, $guild){
$bot->channel->sendMessage("Command Used! Command: {$message->content}", $channel);
}
}
newOurted();
?>

Result:

Example Command

addCommand() Parameters:

  1. Command Name
  2. a Closure to call command class

Delete Message

<?phprequire_once__DIR__ . '/vendor/autoload.php';
useDotenv\Dotenv;
useOurted\Bot;
class Ourted extends Bot
{
public$token;
publicfunction__construct()
{
$dotenv = Dotenv::createImmutable(__DIR__);
$dotenv->load();
$this->token = $_ENV['BOT_TOKEN'];
parent::__construct($this->token, '!');
$this->setBot();
}
publicfunctionsetBot()
{
// Get Channel$channel = $this->channel->getChannel(CHANNEL_ID);
// Delete Messages$message = $this->channel->getMessage($channel, MESSAGE_ID);
$this->channel->deleteMessage($message);
$this->run();
}
}
newOurted();
?>

First wer get channel with getChannel() function. then delete messages with channel and message id.

Delete Bulk Message

<?phprequire_once__DIR__ . '/vendor/autoload.php';
useDotenv\Dotenv;
useOurted\Bot;
class Ourted extends Bot
{
public$token;
publicfunction__construct()
{
$dotenv = Dotenv::createImmutable(__DIR__);
$dotenv->load();
$this->token = $_ENV['BOT_TOKEN'];
parent::__construct($this->token, '!');
$this->setBot();
}
publicfunctionsetBot()
{
// Channel$channel = $this->channel->getChannel(CHANNEL_ID);
$ids = "";
// Count Messagesforeach ($this->channel->getMessages($channel, 99) as$key => $item) {
count($this->channel->getMessages($channel)) -1 == $key?
$ids .= "\"$item->id\"" : $ids.= "\"$item->id\",";
}
// Delete Messages$this->channel->deleteBulkMessage("[{$ids}]", $channel);
$this->run();
}
}
newOurted();
?>

On getMessages() Function must be 2 param setted 1-100 between, integer.

Paramaters:

  1. Ourted\Model\Channel\Channel.php Instance
  2. Integer

Add Role

<?phprequire_once__DIR__ . '/vendor/autoload.php';
useDotenv\Dotenv;
useOurted\Bot;
class Ourted extends Bot
{
public$token;
publicfunction__construct()
{
$dotenv = Dotenv::createImmutable(__DIR__);
$dotenv->load();
$this->token = $_ENV['BOT_TOKEN'];
parent::__construct($this->token, '!');
$this->setBot();
}
publicfunctionsetBot()
{
// Channel$channel = $this->channel->getChannel(CHANNEL_ID);
// Guild: $this->guild->getGuild(742361616728719373)// Name: "Test"// Color: 80 (blue)// Mentionable: true// hoist: true$this->guild->addRole($this->guild->getGuild(742361616728719373), "Test", 80, true, true);
$this->run();
}
}
newOurted();
?>

Get Role

<?phprequire_once__DIR__ . '/vendor/autoload.php';
useDotenv\Dotenv;
useOurted\Bot;
class Ourted extends Bot
{
public$token;
publicfunction__construct()
{
$dotenv = Dotenv::createImmutable(__DIR__);
$dotenv->load();
$this->token = $_ENV['BOT_TOKEN'];
parent::__construct($this->token, '!');
$this->setBot();
}
publicfunctionsetBot()
{
// Channel$channel = $this->channel->getChannel(CHANNEL_ID);
// ->id // ->name// ->color// ->hoist// ->position// ->permissions// ->permissions_new// ->managed// ->mentionableecho$this->guild->getRole($this->guild->getGuild(742361616728719373), 742404691979272203)->name;
$this->run();
}
}
newOurted();
?>

About

The Ourted library provides a discord bot long-process written in PHP.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages