【发布时间】:2021-06-17 05:56:18
【问题描述】:
请修复 Discord 语音消息插件中的错误。
错误:无法启动 MediaRecorder:无法在“MediaDevices”上执行“getUserMedia”:不支持 getUserMedia。
原文:https://github.com/MKSx/Send-Audio-Plugin-BetterDiscord 第 1026 行出错。
有问题的代码:
changeMedia(device=false, changing=false){
const plugin = this;
const change = () => {
plugin.media = null;
plugin.mediaInfo.ready = false;
plugin.mediaInfo.error = false;
navigator.mediaDevices.getUserMedia({audio: (device != false ? device : plugin.settings.devices)}).then(s => {
plugin.media = new MediaRecorder(s);
Logger.log("MediaRecorder started successfully");
plugin.media.addEventListener('dataavailable', e => plugin.onRecordingData(e.data));
plugin.media.addEventListener('start', _ => plugin.onRecordingStateChange(0));
plugin.media.addEventListener('stop', _ => plugin.onRecordingStateChange(1));
plugin.media.addEventListener('pause', _ => plugin.onRecordingStateChange(2));
plugin.media.addEventListener('resume', _ => plugin.onRecordingStateChange(3));
plugin.media.addEventListener('error', error => {
Logger.error('Recording error:', error);
});
plugin.mediaInfo.ready = true;
plugin.mediaInfo.error = false;
if(typeof plugin.buttons == 'object' && plugin.buttons.record instanceof Element)
plugin.buttons.record.disabled = false;
}).catch(err => {
plugin.mediaInfo.ready = false;
plugin.mediaInfo.error = true;
if(typeof plugin.buttons == 'object' &&plugin.buttons.record instanceof Element)
plugin.buttons.record.disabled = true;
Logger.error("Failed to start MediaRecorder:", err.message);
if(!changing){
Logger.log("Changing to the default");
plugin.changeMedia('default', true);
}
});
};
if(this.media instanceof MediaRecorder){
this.mediaInfo.notSave = true;
if(this.media.state != 'inactive')
this.media.stop().then(_ => change()).catch(_ => change());
}
else{
change();
}
}
【问题讨论】:
-
你是如何安装和使用这个插件的?
-
1) 需要安装 -> betterdiscord.app 2) 把js文件移到这里。设置 -> 插件 -> 打开插件文件夹。 (或 BetterDiscord\plugins)。附言此外,对于插件,您需要应用此提交,以便显示来自我的问题的错误。 github.com/MKSx/Send-Audio-Plugin-BetterDiscord/pull/16/commits
-
@Nuril 感谢您的澄清!
标签: javascript plugins discord discord.js