Error while compiling: DiscordServerStatus.cs(39,17): error CS0246: The type or namespace name `Discord' could not be found. Are you missing an assembly reference? Исправь ошибку в коде:Конечно! Вот пример плагина на C# для Rust, который будет отображать онлайн вашего сервера Rust на Discord-сервере в виде бота.
C#:using Discord; using Oxide.Core; using Oxide.Core.Libraries.Covalence; using Oxide.Core.Plugins; using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Oxide.Plugins { [Info("DiscordServerStatus", "YourName", "1.0.0")] [Description("Displays the online status of your Rust server on a Discord server as a bot")] public class DiscordServerStatus : CovalencePlugin { private Configuration config; private Discord.WebSocket.SocketGuild guild; private Discord.WebSocket.SocketTextChannel channel; public class Configuration { public string Token { get; set; } public ulong GuildId { get; set; } public ulong ChannelId { get; set; } public string ServerName { get; set; } } protected override void LoadDefaultConfig() { config = new Configuration { Token = "YOUR_DISCORD_BOT_TOKEN", GuildId = 1234567890, // Replace with your Discord server ID ChannelId = 1234567890, // Replace with your Discord channel ID ServerName = "YOUR_SERVER_NAME" }; } private void OnServerInitialized() { if (string.IsNullOrEmpty(config.Token)) { PrintError("Discord bot token not set! Please set it in the configuration file."); return; } guild = DiscordExtension.GetGuild(config.Token, config.GuildId); channel = DiscordExtension.GetTextChannel(guild, config.ChannelId); if (guild == null || channel == null) { PrintError("Failed to get Discord guild or text channel! Please check your configuration settings."); return; } timer.Repeat(60, 0, UpdateServerStatus); } private void UpdateServerStatus() { var playerCount = BasePlayer.activePlayerList.Count; var embed = new EmbedBuilder() .WithAuthor(config.ServerName, "https://rust.facepunch.com/") .WithColor(new Color(0, 0, 255)) .WithCurrentTimestamp() .WithFooter("Server Status") .WithThumbnailUrl("https://rust.facepunch.com/assets/static/ico/favicon.ico") .WithDescription($"Online Players: {playerCount}"); channel.SendMessageAsync("", false, embed.Build()); } } }
Этот плагин использует библиотеку Covalence и Discord.Net для отправки сообщений на Discord-сервер. Он будет обновлять статус сервера каждые 60 секунд и отправлять его в указанный канал на вашем Discord-сервере.
using Discord;
using Oxide.Core;
using Oxide.Core.Libraries.Covalence;
using Oxide.Core.Plugins;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Oxide.Plugins
{
[Info("DiscordServerStatus", "YourName", "1.0.0")]
[Description("Displays the online status of your Rust server on a Discord server as a bot")]
public class DiscordServerStatus : CovalencePlugin
{
private Configuration config;
private Discord.WebSocket.SocketGuild guild;
private Discord.WebSocket.SocketTextChannel channel;
public class Configuration
{
public string Token { get; set; }
public ulong GuildId { get; set; }
public ulong ChannelId { get; set; }
public string ServerName { get; set; }
}
protected override void LoadDefaultConfig()
{
config = new Configuration
{
Token = "YOUR_DISCORD_BOT_TOKEN",
GuildId = 1234567890, // Replace with your Discord server ID
ChannelId = 1234567890, // Replace with your Discord channel ID
ServerName = "YOUR_SERVER_NAME"
};
}
private void OnServerInitialized()
{
if (string.IsNullOrEmpty(config.Token))
{
PrintError("Discord bot token not set! Please set it in the configuration file.");
return;
}
guild = DiscordExtension.GetGuild(config.Token, config.GuildId);
channel = DiscordExtension.GetTextChannel(guild, config.ChannelId);
if (guild == null || channel == null)
{
PrintError("Failed to get Discord guild or text channel! Please check your configuration settings.");
return;
}
timer.Repeat(60, 0, UpdateServerStatus);
}
private void UpdateServerStatus()
{
var playerCount = BasePlayer.activePlayerList.Count;
var embed = new EmbedBuilder()
.WithAuthor(config.ServerName, "https://rust.facepunch.com/")
.WithColor(new Color(0, 0, 255))
.WithCurrentTimestamp()
.WithFooter("Server Status")
.WithThumbnailUrl("https://rust.facepunch.com/assets/static/ico/favicon.ico")
.WithDescription($"Online Players: {playerCount}");
channel.SendMessageAsync("", false, embed.Build());
}
}
}