discord添加SetGame / SetStatus

时间:2017-06-15 23:26:59

标签: c# api bots discord

我想知道如何设置"玩"对于C#中的bot,我使用的是.NET

在Discord上,文字通常在你的名下,并说你正在玩的当前游戏,我希望它显示自定义信息,当然我知道机器人不玩游戏我只是想让它说出我想要的东西它可以说,例如"扮演好人", "玩osu!"。 "玩Google Chrome",

这是我代码的一部分,请帮助我。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Discord;
using Discord.Commands;

namespace Kosei_Arima
{
class MyBot
{
    DiscordClient discord;
    CommandService commands;

    Random rand;

    string[] freshestMemes;

    public MyBot()
    {
        rand = new Random();

        freshestMemes = new string[]
        {
            "mem/mem1.jpg", //0
            "mem/mem2.jpg", //1
            "mem/mem3.png", //2
            "mem/mem4.png", //3
            "mem/mem5.png", //4
            "mem/mem6.jpg", //5
            "mem/mem7.jpg", //6
            "mem/mem8.jpg", //7
            "mem/mem9.jpg", //8
            "mem/mem10.jpg", //9
            "mem/mem11.jpg", //10
            "mem/mem12.jpg", //11
            "mem/mem13.jpg", //12
            "mem/mem14.jpg", //13
            "mem/mem15.jpg", //14
            "mem/mem16.jpg", //15
            "mem/mem17.jpg", //16
            "mem/mem18.jpg", //17
            "mem/mem19.jpg", //18
            "mem/mem20.jpg", //19
            "mem/mem21.jpg", //20
            "mem/mem22.png"  //21
        };

        discord = new DiscordClient(x =>
        {
            x.LogLevel = LogSeverity.Info;
            x.LogHandler = Log;
        });

        discord.UsingCommands(x =>
        {
            x.PrefixChar = '-';
            x.AllowMentionPrefix = true;
        });

        commands = discord.GetService<CommandService>();

        RegisterMemeCommand();
        RegisterHelpCommand();
        RegisterPurgeCommand();
        RegisterPruneCommand();
        RegisterDisconnectCommand();
        RegisterEchoCommand();

        OnJoin();
        OnLeave();

        discord.MessageReceived += Discord_MessageReceived;

        discord.ExecuteAndWait(async () =>
        {
            await discord.Connect("TokenGoesHere", TokenType.Bot);
        });
    }

2 个答案:

答案 0 :(得分:2)

您应该能够使用DiscordClient的SetGameAsync(string name, string streamurl = null, StreamType streamtype = StreamType.NotStreaming)函数来执行此操作(给出具有它们的参数的默认值)。它是异步的,所以你需要等待它(适用于异步函数的所有标准事物都适用于此)。如果您只想设置游戏,则使用非常简单:

await discord.SetGameAsync("Google Chrome");

对于Twitch流(Discord.net似乎不支持任何其他内容):

await discord.SetGameAsync("Overwatch", "https://twitch.tv/yourstreamhere", 
  StreamType.Twitch);

答案 1 :(得分:-2)

        client.ExecuteAndWait(async () =>
        {
            await client.Connect("your fkin token is here", TokenType.Bot);
            client.SetGame("<whatever you want>");
        });