display errors to users properly
This commit is contained in:
parent
19d121a572
commit
cadec6cdfe
2 changed files with 8 additions and 4 deletions
|
@ -12,11 +12,16 @@ export function makeBot() {
|
||||||
client.on("MESSAGE_CREATE", (message) => {
|
client.on("MESSAGE_CREATE", (message) => {
|
||||||
if (message.content.startsWith("$ ")) {
|
if (message.content.startsWith("$ ")) {
|
||||||
const command = message.content.substring(2, message.content.length);
|
const command = message.content.substring(2, message.content.length);
|
||||||
handleCommand(command, (_streamName, streamContent) => {
|
const result = handleCommand(command, (_streamName, streamContent) => {
|
||||||
client.api("POST", `/channels/${message.channel_id}/messages`, {
|
client.api("POST", `/channels/${message.channel_id}/messages`, {
|
||||||
content: streamContent
|
content: streamContent
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
if (result.error) {
|
||||||
|
client.api("POST", `/channels/${message.channel_id}/messages`, {
|
||||||
|
content: `error: ${result.error}`
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -191,14 +191,13 @@ export function handleCommand(message, displayFunc) {
|
||||||
const { error: tokError, tokens } = tokenize(message);
|
const { error: tokError, tokens } = tokenize(message);
|
||||||
if (tokError) {
|
if (tokError) {
|
||||||
return {
|
return {
|
||||||
error: `error: tokenize: ${tokError}`
|
error: `tokenize: ${tokError}`
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const { error: insError, instructions } = tokensToInstructions(tokens);
|
const { error: insError, instructions } = tokensToInstructions(tokens);
|
||||||
console.log(instructions);
|
|
||||||
if (insError) {
|
if (insError) {
|
||||||
return {
|
return {
|
||||||
error: `error: tokensToInstructions: ${insError}`
|
error: `tokensToInstructions: ${insError}`
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue