Pai*_*eYT 4 c# api bots discord
我想知道如何在 C# 中为机器人设置“播放”,我正在使用 .NET
在 Discord 上,文本通常位于您的名字下方,并显示您当前正在玩的游戏,我希望它显示自定义消息,当然我知道机器人没有在玩游戏,我只是想让它说一些我想说的话,例如“扮演好人”、“扮演osu!”。“正在玩谷歌浏览器”,
这是我的代码的一部分,请帮助我。
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);
});
}
Run Code Online (Sandbox Code Playgroud)
您应该能够使用 DiscordClient 的SetGameAsync(string name, string streamurl = null, StreamType streamtype = StreamType.NotStreaming)函数来执行此操作(给出了包含它们的参数的默认值)。它是一个异步函数,因此您需要等待它(并且适用于异步函数的所有标准内容都适用于此处)。如果您只想设置游戏,那么使用非常简单:
await discord.SetGameAsync("Google Chrome");
Run Code Online (Sandbox Code Playgroud)
对于 Twitch 流(Discord.net 似乎不支持其他任何内容):
await discord.SetGameAsync("Overwatch", "https://twitch.tv/yourstreamhere",
StreamType.Twitch);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10057 次 |
| 最近记录: |