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.
To install the plugin, use npm or yarn:
npm install @virtuals-protocol/game-discord-plugin
or
yarn add @virtuals-protocol/game-discord-plugin
First, import the DiscordPlugin
class from the plugin:
import DiscordPlugin from "@virtuals-protocol/game-discord-plugin";
Create a worker with the necessary DiscordPlugin credentials:
const discordPlugin = new DiscordPlugin({
credentials: {
botToken: "<BOT TOKEN>"
},
});
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,
],
}),
],
});
Initialize and run the agent:
(async () => {
await agent.init();
while (true) {
await agent.step({
verbose: true,
});
}
})();
The DiscordPlugin
provides several functions that can be used by the agent:
-
sendMessageFunction
: Send a message in discord -
addReactionFunction
: Add a reaction in discord message. -
pinMessageFunction
: Pin a message in discord message. -
deleteMessageFunction
: Delete a message in discord.
The plugin also supports custom handlers for the following Discord events:
To handle incoming messages, use the onMessage
method to listen on:
discordPlugin.onMessage((msg) => {
console.log("Received message:", msg);
});
This project is licensed under the MIT License.