mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
fix: skip problematic name-value pairs in encodeCQCode to prevent undefined errors
Added logic to skip name-value pairs in encodeCQCode when value cannot be converted to string, preventing errors caused by undefined values. This ensures the function can handle such cases gracefully and continue processing other valid data.
This commit is contained in:
parent
bc4511e175
commit
c9374ff515
@ -61,6 +61,14 @@ export function encodeCQCode(data: OB11MessageData) {
|
||||
let result = '[CQ:' + data.type
|
||||
for (const name in data.data) {
|
||||
const value = data.data[name]
|
||||
try {
|
||||
// Check if the value can be converted to a string
|
||||
value.toString();
|
||||
} catch (error) {
|
||||
// If it can't be converted, skip this name-value pair
|
||||
// console.warn(`Skipping problematic name-value pair. Name: ${name}, Value: ${value}`);
|
||||
continue;
|
||||
}
|
||||
result += `,${name}=${CQCodeEscape(value)}`
|
||||
}
|
||||
result += ']'
|
||||
|
Loading…
x
Reference in New Issue
Block a user