Skip to content

BotSoundEvent

Triggered when a bot gets a sound that a player would hear.

A bot has no speakers, so this event is how a spell hears what a bot hears, for example to play-test a mini-game: does the player get the fanfare at the end. It fires once for each bot that gets the sound.

The server tells a player of the sounds it plays for them, like those of /playsound, and of most sounds of the world around them: a door, an explosion, a mob. It doesn't tell them of what their own client plays by itself, like their own footsteps. Near mobs a bot gets many sounds, so look at sound before anything else.

This event cannot be canceled.

Example

local bot = Bot:spawn("Bob", spell.pos)
local queue = spell:collect("BotSoundEvent")
spell:execute("playsound minecraft:entity.player.levelup master Bob")
local evt = queue:next(20) --[[@as BotSoundEvent?]]
if evt then
  print(evt.bot.name .. " hears " .. evt.sound)
end

Fields

bot: Bot — Read-Only

A reference to the bot that got the sound.

category: string — Read-Only

The sound category, as in /playsound: "master", "music", "record", "weather", "block", "hostile", "neutral", "player", "ambient", "voice" or "ui".

name: string — Read-Only

The name of the event.

pitch: number — Read-Only

The pitch of the sound; 1 is its normal pitch.

pos: Vec3? — Read-Only

A copy of the position the sound comes from. nil for the sound of an entity that is gone.

sound: string — Read-Only

The ID of the sound, like "entity.player.levelup".

volume: number — Read-Only

The volume of the sound; 1 is its normal volume.