private async void Gateway_OnMessageCreated(object sender, MessageEventArgs e) { Shard shard = e.Shard; DiscordMessage message = e.Message; if (message.Author.Id == shard.UserId) { // Ignore messages created by our bot. return; } if (message.Content == "ping") { try { // Reply to the user who posted "!ping". await http.CreateMessage(message.ChannelId, $"<@!{message.Author.Id}> Pong!"); } catch (DiscordHttpApiException) { } } }
/// <summary> /// Creates a message in this channel. /// <para>Note: Bot user accounts must connect to the Gateway at least once before being able to send messages.</para> /// <para>Requires <see cref="DiscordPermission.SendMessages"/>.</para> /// </summary> /// <param name="content">The message text content.</param> /// <returns>Returns the created message.</returns> /// <exception cref="DiscordHttpApiException"></exception> public Task <DiscordMessage> CreateMessage(string content) { return(http.CreateMessage(Id, content)); }
internal void Respond(Snowflake channel, string message) { client.CreateMessage(channel, message); }