@virtuals-protocol/game-discord-plugin
v0.1.4
Published
This plugin allows you to integrate Discord functionalities into your Virtuals Game. With this plugin, you can send message, pin message, add reaction and delete message in Discord.
Downloads
8
Readme
Discord Plugin for Virtuals Game
This plugin allows you to integrate Discord functionalities into your Virtuals Game. With this plugin, you can send message, pin message, add reaction and delete message in Discord.
Installation
To install the plugin, use npm or yarn:
npm install @virtuals-protocol/game-discord-pluginor
yarn add @virtuals-protocol/game-discord-pluginUsage
Importing the Plugin
First, import the DiscordPlugin class from the plugin:
import DiscordPlugin from "@virtuals-protocol/game-discord-plugin";Creating a Worker
Create a worker with the necessary DiscordPlugin credentials:
const discordPlugin = new DiscordPlugin({
credentials: {
botToken: "<BOT TOKEN>"
},
});Creating an Agent
Create an agent and add the worker to it:
import { GameAgent } from "@virtuals-protocol/game";
const agent = new GameAgent("<API_KEY>", {
name: "Discord Bot",
goal: "increase engagement and grow follower count",
description: "A bot that can reply message, add reaction, pin message and delete message in Discord.",
workers: [
discordPlugin.getWorker({
// Define the functions that the worker can perform, by default it will use the all functions defined in the plugin
functions: [
discordPlugin.sendMessageFunction,
discordPlugin.addReactionFunction,
discordPlugin.pinMessageFunction,
discordPlugin.deleteMessageFunction,
],
}),
],
});Running the Agent
Initialize and run the agent:
(async () => {
await agent.init();
while (true) {
await agent.step({
verbose: true,
});
}
})();Available Functions
The DiscordPlugin provides several functions that can be used by the agent:
sendMessageFunction: Send a message in discordaddReactionFunction: Add a reaction in discord message.pinMessageFunction: Pin a message in discord message.deleteMessageFunction: Delete a message in discord.
Event Handlers
The plugin also supports custom handlers for the following Discord events:
Handling Incoming Messages
To handle incoming messages, use the onMessage method to listen on:
discordPlugin.onMessage((msg) => {
console.log("Received message:", msg);
});License
This project is licensed under the MIT License.
