当前位置: 首页>>代码示例>>C#>>正文


C# Channel.SendMessage方法代码示例

本文整理汇总了C#中Discord.Channel.SendMessage方法的典型用法代码示例。如果您正苦于以下问题:C# Channel.SendMessage方法的具体用法?C# Channel.SendMessage怎么用?C# Channel.SendMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Discord.Channel的用法示例。


在下文中一共展示了Channel.SendMessage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CanRun

        public bool CanRun(Command command, User user, Channel channel, out string error) {
            error = null;

            if (channel.IsPrivate)
                return true;

            try {
                //is it a permission command?
                // if it is, check if the user has the correct role
                // if yes return true, if no return false
                if (command.Category == "Permissions")
                    if (user.Server.IsOwner || user.HasRole(PermissionHelper.ValidateRole(user.Server, PermissionsHandler.GetServerPermissionsRoleName(user.Server))))
                        return true;
                    else
                        throw new Exception($"You don't have the necessary role (**{PermissionsHandler._permissionsDict[user.Server].PermissionsControllerRole}**) to change permissions.");

                var permissionType = PermissionsHandler.GetPermissionBanType(command, user, channel);

                string msg;

                switch (permissionType) {
                    case PermissionsHandler.PermissionBanType.None:
                        return true;
                    case PermissionsHandler.PermissionBanType.ServerBanCommand:
                        msg = $"**{command.Text}** command has been banned from use on this **server**.";
                        break;
                    case PermissionsHandler.PermissionBanType.ServerBanModule:
                        msg = $"**{command.Category}** module has been banned from use on this **server**.";
                        break;
                    case PermissionsHandler.PermissionBanType.ChannelBanCommand:
                        msg = $"**{command.Text}** command has been banned from use on this **channel**.";
                        break;
                    case PermissionsHandler.PermissionBanType.ChannelBanModule:
                        msg = $"**{command.Category}** module has been banned from use on this **channel**.";
                        break;
                    case PermissionsHandler.PermissionBanType.RoleBanCommand:
                        msg = $"You do not have a **role** which permits you the usage of **{command.Text}** command.";
                        break;
                    case PermissionsHandler.PermissionBanType.RoleBanModule:
                        msg = $"You do not have a **role** which permits you the usage of **{command.Category}** module.";
                        break;
                    case PermissionsHandler.PermissionBanType.UserBanCommand:
                        msg = $"{user.Mention}, You have been banned from using **{command.Text}** command.";
                        break;
                    case PermissionsHandler.PermissionBanType.UserBanModule:
                        msg = $"{user.Mention}, You have been banned from using **{command.Category}** module.";
                        break;
                    default:
                        return true;
                }
                if (PermissionsHandler._permissionsDict[user.Server].Verbose) //if verbose - print errors
                    Task.Run(() => channel.SendMessage(msg));
                return false;
            } catch (Exception ex) {
                if (PermissionsHandler._permissionsDict[user.Server].Verbose) //if verbose - print errors
                    Task.Run(() => channel.SendMessage(ex.Message));
                return false;
            }
        }
开发者ID:TheFerty7,项目名称:NadekoBot,代码行数:59,代码来源:PermissionChecker.cs

示例2: MainAsync

        public static async Task MainAsync(Server server, Channel channel, User user, IEnumerable<string> args)
        {
            bool isError = false;
            string errorMessage = "";

            try
            {
                Color c = null;
                Role r = null;
                string colorName = null;

                if (args.FirstOrDefault() != null)
                    colorName = args.FirstOrDefault().ToLower();

                c = GetRoleColor(colorName);

                if (colorName != null && c != null)
                {

                    if ((r = GetRole(Capitalize(args.First().ToLower()), server.Roles)) != null)
                    {
                        await CheckForRolesAsync(user, server.Roles);
                        await user.AddRoles(r);
                    }
                    else
                    {
                        await CheckForRolesAsync(user, server.Roles);
                        string roleName = string.Format("{0}{1}", rolePrefix, Capitalize(colorName));
                        await user.AddRoles(await server.CreateRole(roleName, color: c));
                    }
                }
                else
                {
                    await channel.SendMessage(user.Mention + " Wrong colour input, check help for working colours.");
                }
            }
            catch (Exception ex)
            {
                isError = true;
                errorMessage = ex.Message.ToString();
            }

            if (isError)
                await channel.SendMessage(user.Mention + " " + errorMessage);

            await DeleteUnusedRolesAsync(server.Roles);
        }
开发者ID:XanderBras,项目名称:ColourBot,代码行数:47,代码来源:ColourCommand.cs

示例3: ExecuteCommand

 public  async void ExecuteCommand(Channel channel, Message message)
 {
     await channel.SendIsTyping();
     Thread.Sleep(5000);
     await
         channel.SendMessage(
             "What the fuck did you just fucking say about me, you little bitch? I’ll have you know I graduated top of my class in the Navy Seals, and I’ve been involved in numerous secret raids on Al-Quaeda, and I have over 300 confirmed kills. I am trained in gorilla warfare and I’m the top sniper in the entire US armed forces. You are nothing to me but just another target. I will wipe you the fuck out with precision the likes of which has never been seen before on this Earth, mark my fucking words. You think you can get away with saying that shit to me over the Internet? Think again, fucker. As we speak I am contacting my secret network of spies across the USA and your IP is being traced right now so you better prepare for the storm, maggot. The storm that wipes out the pathetic little thing you call your life. You’re fucking dead, kid. I can be anywhere, anytime, and I can kill you in over seven hundred ways, and that’s just with my bare hands. Not only am I extensively trained in unarmed combat, but I have access to the entire arsenal of the United States Marine Corps and I will use it to its full extent to wipe your miserable ass off the face of the continent, you little shit. If only you could have known what unholy retribution your little “clever” comment was about to bring down upon you, maybe you would have held your fucking tongue. But you couldn’t, you didn’t, and now you’re paying the price, you goddamn idiot. I will shit fury all over you and you will drown in it. You’re fucking dead, kiddo.");
 }
开发者ID:msciotti,项目名称:Discord-Bot,代码行数:8,代码来源:MasonCommand.cs

示例4: ExecutePlaylist

        public static async Task ExecutePlaylist(IAudioClient voiceClient, List<string> playlist, Channel jamSessionChatChannel)
        {
            while (playlist.Count > 0)
            {
                string strCmdText;
                // TODO: Make this better
                Process cmdProcess = new Process();
                cmdProcess.StartInfo.FileName = "cmd.exe";
                cmdProcess.StartInfo.UseShellExecute = false;
                cmdProcess.StartInfo.RedirectStandardOutput = true;
                cmdProcess.StartInfo.RedirectStandardInput = true;
                cmdProcess.Start();

                /* Change for local/prod */
                //cmdProcess.StandardInput.WriteLine(@"del C:\Users\Tony\Desktop\Misc\DiscordBot\DiscordMusicBot\DiscordMusicBot\bin\assets\current.mp3");
                cmdProcess.StandardInput.WriteLine(@"del C:\MilliaBot\MilliaBot\assets\current.mp3");

                //cmdProcess.StartInfo.WorkingDirectory = @"cd C:\Users\Tony\Desktop\Misc\DiscordBot\DiscordMusicBot\DiscordMusicBot\bin\Debug";
                cmdProcess.StartInfo.WorkingDirectory = @"cd C:\MilliaBot\MilliaBot\Debug";

                strCmdText =
                    "youtube-dl -o ../assets/current.mp3 --extract-audio --audio-format mp3 " +
                    playlist.First();
                cmdProcess.StandardInput.WriteLine(strCmdText);

                await Task.Delay(5555);

                string file = "../assets/current.mp3";

                await jamSessionChatChannel.SendMessage("Now playing: " + playlist.First());
                if (playlist.Count > 1)
                {
                    await jamSessionChatChannel.SendMessage("Songs left in the playlist: " + playlist.Count);
                }

                await PlayMusic(voiceClient, file);

                if (playlist.Count > 0)
                    playlist.RemoveAt(0);
            }
        }
开发者ID:SorAnoHikari,项目名称:MilliaBot,代码行数:41,代码来源:MusicService.cs

示例5: HelpAsync

        public static async Task HelpAsync(Server server, Channel channel, User user, IEnumerable<string> args)
        {
            bool isError = false;
            string errorMessage = "";

            try
            {
                Channel ch = await user.CreatePMChannel();
                await ch.SendMessage(WriteHelpMessage());
            }
            catch (Exception ex)
            {
                isError = true;
                errorMessage = ex.Message.ToString();
            }

            if (isError)
                await channel.SendMessage(user.Mention + " " + errorMessage);
        }
开发者ID:XanderBras,项目名称:ColourBot,代码行数:19,代码来源:ColourCommand.cs

示例6: ExecuteCommand

 public  async void ExecuteCommand(Channel channel, Message message)
 {
     try
     {
         var discordId = message.User.Id;
         var builder = new MySqlConnectionStringBuilder
         {
             Database = "mediabiz_DiscordBot",
             Server = "masonsciotti.com",
             Port = 3306,
             UserID = "mediabiz_msciott",
             Password = "wehd0ta1993"
         };
         var conn = new MySqlConnection(builder.ConnectionString);
         conn.Open();
         var command =
             new MySqlCommand($"SELECT steam_id FROM SteamIdRegistration WHERE discord_id = {discordId}", conn);
         var steamId = command.ExecuteScalar();
         var latestMatchId =
             SteamWebAPI.Game()
                 .Dota2()
                 .IDOTA2Match()
                 .GetMatchHistory()
                 .Account(SteamIdentity.FromSteamID(((long) steamId)))
                 .GetResponse()
                 .Data.Matches.FirstOrDefault()?
                 .MatchID;
         await
             channel.SendMessage("Last match for " + message.User.Mention + ": http://www.dotabuff.com/matches/" +
                                 latestMatchId);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
     }
 }
开发者ID:msciotti,项目名称:Discord-Bot,代码行数:36,代码来源:LatestMatchCommand.cs

示例7: ExecuteCommand

 public  async void ExecuteCommand(Channel channel, Message message)
 {
     await channel.SendMessage("༼ ºل͜º ༽ºل͜º ༽ºل͜º ༽ HEY @everyone GET IN HERE ༼ ºل͜º༼ ºل͜º༼ ºل͜º ༽");
 }
开发者ID:msciotti,项目名称:Discord-Bot,代码行数:4,代码来源:PileOnCommand.cs

示例8: ExecuteCommand

 public async void ExecuteCommand(Channel channel, Message message)
 {
     await channel.SendMessage("http://i.imgur.com/Ek817Gh.jpg");
 }
开发者ID:msciotti,项目名称:Discord-Bot,代码行数:4,代码来源:ArrowCommand.cs

示例9: ExecuteCommand

 public  async void ExecuteCommand(Channel channel, Message message)
 {           
     await channel.SendMessage("https://45.media.tumblr.com/4b38cf29e942d17d2d9ffc761ecca2c0/tumblr_n2jgzxjXxT1tod5n6o1_400.gif");            
 }
开发者ID:msciotti,项目名称:Discord-Bot,代码行数:4,代码来源:PaulCommand.cs

示例10: ExecuteCommand

 public  void ExecuteCommand(Channel channel, Message message)
 {
     channel.SendMessage(
         "👌👀👌👀👌👀👌👀👌👀 good shit go౦ԁ sHit👌 thats ✔ some good👌👌shit right👌👌there👌👌👌 right✔there ✔✔if i do ƽaү so my self 💯 i say so 💯 thats what im talking about right there right there (chorus: ʳᶦᵍʰᵗ ᵗʰᵉʳᵉ) mMMMMᎷМ💯 👌👌 👌НO0ОଠOOOOOОଠଠOoooᵒᵒᵒᵒᵒᵒᵒᵒᵒ👌 👌👌 👌 💯 👌 👀 👀 👀 👌👌Good shit");
 }
开发者ID:msciotti,项目名称:Discord-Bot,代码行数:5,代码来源:GoodShitCommand.cs

示例11: ExecuteCommand

 public  void ExecuteCommand(Channel channel, Message message)
 {
     channel.SendMessage("http://i.imgur.com/gmIkoPP.gifv");
 }
开发者ID:msciotti,项目名称:Discord-Bot,代码行数:4,代码来源:TrexCommand.cs

示例12: ExecuteCommand

 public async void ExecuteCommand(Channel channel, Message message)
 {
     await channel.SendMessage(HelperMethods.PickAnAyy());
 }
开发者ID:msciotti,项目名称:Discord-Bot,代码行数:4,代码来源:AyyCommand.cs

示例13: QueueSong

        public static async Task QueueSong(User queuer, Channel textCh, Channel voiceCh, string query, bool silent = false, MusicType musicType = MusicType.Normal)
        {
            if (voiceCh == null || voiceCh.Server != textCh.Server)
            {
                if (!silent)
                    await textCh.SendMessage("💢 You need to be in a voice channel on this server.\n If you are already in a voice channel, try rejoining.").ConfigureAwait(false);
                throw new ArgumentNullException(nameof(voiceCh));
            }
            if (string.IsNullOrWhiteSpace(query) || query.Length < 3)
                throw new ArgumentException("💢 Invalid query for queue song.", nameof(query));

            var musicPlayer = MusicPlayers.GetOrAdd(textCh.Server, server =>
            {
                float vol = SpecificConfigurations.Default.Of(server.Id).DefaultMusicVolume;
                var mp = new MusicPlayer(voiceCh, vol);


                Message playingMessage = null;
                Message lastFinishedMessage = null;
                mp.OnCompleted += async (s, song) =>
                {
                    if (song.PrintStatusMessage)
                    {
                        try
                        {
                            if (lastFinishedMessage != null)
                                await lastFinishedMessage.Delete().ConfigureAwait(false);
                            if (playingMessage != null)
                                await playingMessage.Delete().ConfigureAwait(false);
                            lastFinishedMessage = await textCh.SendMessage($"🎵`Finished`{song.PrettyName}").ConfigureAwait(false);
                            if (mp.Autoplay && mp.Playlist.Count == 0 && song.SongInfo.Provider == "YouTube")
                            {
                                await QueueSong(queuer.Server.CurrentUser, textCh, voiceCh, (await SearchHelper.GetRelatedVideoIds(song.SongInfo.Query, 4)).ToList().Shuffle().FirstOrDefault(), silent, musicType).ConfigureAwait(false);
                            }
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e);
                        }
                    }
                };
                mp.OnStarted += async (s, song) =>
                {
                    if (song.PrintStatusMessage)
                    {
                        var sender = s as MusicPlayer;
                        if (sender == null)
                            return;

                        try
                        {

                            var msgTxt = $"🎵`Playing`{song.PrettyName} `Vol: {(int)(sender.Volume * 100)}%`";
                            playingMessage = await textCh.SendMessage(msgTxt).ConfigureAwait(false);
                        }
                        catch { }
                    }
                };
                return mp;
            });
            Song resolvedSong;
            try
            {
                musicPlayer.ThrowIfQueueFull();
                resolvedSong = await Song.ResolveSong(query, musicType).ConfigureAwait(false);

                musicPlayer.AddSong(resolvedSong, queuer.Name);
            }
            catch (PlaylistFullException)
            {
                await textCh.SendMessage($"🎵 `Queue is full at {musicPlayer.MaxQueueSize}/{musicPlayer.MaxQueueSize}.` ");
                throw;
            }
            if (!silent)
            {
                var queuedMessage = await textCh.SendMessage($"🎵`Queued`{resolvedSong.PrettyName} **at** `#{musicPlayer.Playlist.Count + 1}`").ConfigureAwait(false);
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                Task.Run(async () =>
                                {
                                    await Task.Delay(10000).ConfigureAwait(false);
                                    try
                                    {
                                        await queuedMessage.Delete().ConfigureAwait(false);
                                    }
                                    catch { }
                                }).ConfigureAwait(false);
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            }
        }
开发者ID:Ryonez,项目名称:Lucy,代码行数:89,代码来源:MusicModule.cs

示例14: ExecuteCommand

 async public void ExecuteCommand(Channel channel, Message message)
 {
     await channel.SendMessage("https://i.redd.it/1orjrm27jscx.jpg");
 }
开发者ID:msciotti,项目名称:Discord-Bot,代码行数:4,代码来源:HarambeCommand.cs

示例15: QueueSong

        private async Task QueueSong(Channel textCh, Channel voiceCh, string query, bool silent = false, MusicType musicType = MusicType.Normal)
        {
            if (voiceCh == null || voiceCh.Server != textCh.Server)
            {
                if (!silent)
                    await textCh.SendMessage("💢 You need to be in a voice channel on this server.\n If you are already in a voice channel, try rejoining.");
                throw new ArgumentNullException(nameof(voiceCh));
            }
            if (string.IsNullOrWhiteSpace(query) || query.Length < 3)
                throw new ArgumentException("💢 Invalid query for queue song.", nameof(query));

            var musicPlayer = MusicPlayers.GetOrAdd(textCh.Server, server =>
            {
                float? vol = null;
                float throwAway;
                if (DefaultMusicVolumes.TryGetValue(server.Id, out throwAway))
                    vol = throwAway;
                var mp = new MusicPlayer(voiceCh, vol);


                Message playingMessage = null;
                Message lastFinishedMessage = null;
                mp.OnCompleted += async (s, song) =>
                {
                    if (song.PrintStatusMessage)
                    {
                        try
                        {
                            if (lastFinishedMessage != null)
                                await lastFinishedMessage.Delete();
                            if (playingMessage != null)
                                await playingMessage.Delete();
                            lastFinishedMessage = await textCh.SendMessage($"🎵`Finished`{song.PrettyName}");
                        }
                        catch { }
                    }
                };
                mp.OnStarted += async (s, song) =>
                {
                    if (song.PrintStatusMessage)
                    {
                        var sender = s as MusicPlayer;
                        if (sender == null)
                            return;

                        try
                        {

                            var msgTxt = $"🎵`Playing`{song.PrettyName} `Vol: {(int)(sender.Volume * 100)}%`";
                            playingMessage = await textCh.SendMessage(msgTxt);
                        }
                        catch { }
                    }
                };
                return mp;
            });
            var resolvedSong = await Song.ResolveSong(query, musicType);
            resolvedSong.MusicPlayer = musicPlayer;

            musicPlayer.AddSong(resolvedSong);
            if (!silent)
            {
                var queuedMessage = await textCh.SendMessage($"🎵`Queued`{resolvedSong.PrettyName} **at** `#{musicPlayer.Playlist.Count}`");
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                Task.Run(async () =>
                {
                    await Task.Delay(10000);
                    try
                    {
                        await queuedMessage.Delete();
                    }
                    catch { }
                });
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            }
        }
开发者ID:magicvoid1,项目名称:NadekoBot,代码行数:76,代码来源:MusicModule.cs


注:本文中的Discord.Channel.SendMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。