Backtrace (make sure to run RUST_BACKTRACE=1): N/A
Minimal test case if possible:
I added a message command to my guild that works as long as the message has no reactions. As soon as the message has a reaction my bot doesn't get any sort of InteractionCreate event. I figured out how to log the raw event data and discovered that when calling a message command on the same message with a reaction the Event from the raw_event function says that it received an unknown event (even though the unknown event is of kind: "INTERACTION_CREATE"). But if I remove the reaction and try the message command again it comes through as the proper InteractionCreate event.
use serenity::{
all::{
CommandType, Context, CreateCommand, CreateInteractionResponse,
CreateInteractionResponseMessage, Event, EventHandler, GatewayIntents, GuildId,
Interaction, RawEventHandler, Ready,
},
async_trait, Client,
};
struct Bot {}
#[async_trait]
impl EventHandler for Bot {
async fn interaction_create(&self, ctx: Context, interaction: Interaction) {
println!("Got interaction!");
match interaction {
Interaction::Command(command) => {
println!("Command interaction: {}", command.data.name);
let data = CreateInteractionResponseMessage::new()
.content("Success")
.ephemeral(true);
let builder = CreateInteractionResponse::Message(data);
if let Err(why) = command.create_response(&ctx.http, builder).await {
println!("Cannot respond to slash command: {why}");
}
}
_ => {
println!("Unable to respond to interaction");
}
}
}
async fn ready(&self, ctx: Context, ready: Ready) {
println!("{} is connected!", ready.user.name);
let guild_id = GuildId::new(
std::env::var("GUILD_ID")
.expect("Expected GUILD_ID in the environment or .env file")
.parse()
.expect("GUILD_ID must be an integer"),
);
let commands = guild_id
.set_commands(
&ctx.http,
vec![CreateCommand::new("message_command_test").kind(CommandType::Message)],
)
.await;
println!("I now have the following guild slash commandssss: {commands:#?}");
}
}
#[async_trait]
impl RawEventHandler for Bot {
async fn raw_event(&self, _ctx: Context, ev: Event) {
println!("{:#?}", ev);
}
}
#[tokio::main]
async fn main() {
dotenv::dotenv().ok();
let bot = Bot {};
let mut client = Client::builder(
std::env::var("DISCORD_TOKEN")
.expect("Expected DISCORD_TOKEN in the environment or .env file"),
GatewayIntents::all(),
)
// .event_handler(bot)
.raw_event_handler(bot)
.await
.expect("Error creating client");
if let Err(why) = client.start().await {
println!("Client error: {:?}", why);
}
}
The raw event data for a message command successfully run on a message without a reaction
Serenity version: 0.12.2
Rust version (
rustc -V
): 1.77.0Backtrace (make sure to run
RUST_BACKTRACE=1
): N/AMinimal test case if possible: I added a message command to my guild that works as long as the message has no reactions. As soon as the message has a reaction my bot doesn't get any sort of
InteractionCreate
event. I figured out how to log the raw event data and discovered that when calling a message command on the same message with a reaction the Event from theraw_event
function says that it received an unknown event (even though the unknown event is ofkind: "INTERACTION_CREATE"
). But if I remove the reaction and try the message command again it comes through as the proper InteractionCreate event.The raw event data for a message command successfully run on a message without a reaction
Raw event data for a message command on the same message after adding a reaction