- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个可以从我的电脑播放音乐的机器人。有没有办法从发送消息的人的计算机上播放歌曲?我的想法是使用 message.author
以某种方式访问该人的 session 并进入他们的驱动器。这是我的机器人。它可以加入语音 channel ,从本地文件路径创建播放列表,使用停止/暂停/播放/下一个/上一个控件启动播放列表或单个文件:
import discord
import os.path
import logging
import asyncio
from os import path
global ready
global vc
global source
global songQueue
global songIndex
global commandList
global stopPlaylist
ready = False
stopPlaylist = False
songQueue = []
songIndex = 0
logger = logging.getLogger('discord')
logger.setLevel(logging.DEBUG)
handler = logging.FileHandler(filename='D:\DnD\DiscordBot\discord.log', encoding='utf-8', mode='w')
handler.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s'))
logger.addHandler(handler)
client = discord.Client()
commands = [
'!connect\nConnect to a voice channel by channel id. Use !channels to find the desired id.\nExample Command: !connect 827202170973323305\n\n',
'!channels\nLists all voice channels and their connection id.\n\n',
'!add\nAdd a file path to the playlist.\nExample Command: !add D:\\DnD\\DiscordBot\\mySong.mp3\n\n',
'!delete\nDeletes the last song added to the playlist.\n\n',
'!view\nDisplays the current playlist, in order.\n\n',
'!playlist\nStarts the playlist from the beginning, or optionally add a number as the start position.\nExample Command: !playlist 3\n\n',
'!playSong\nPlays a specified file.\nExample Command: !playSong D:\\DnD\\DiscordBot\\mySong.mp3\n\n',
'!next\nPlays next song in playlist.\n\n',
'!prev\nPlays previous song in playlist.\n\n',
'!stop\nStops all music song. Playlist will restart from the beginning.\n\n',
'!pause\nPauses the current song. Restart with !resumeSong.\n\n',
'!resume\nResumes the current song.\n\n'
'!status\nLets you know if the bot thinks it is playing music.'
]
commandList=''
for command in commands:
commandList+=command
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
@client.event
async def on_message(message):
global ready
global vc
global source
global songQueue
global songIndex
global commandList
global stopPlaylist
if message.author == client.user:
return
#!help
if message.content.startswith('!help'):
await message.channel.send('{0}'.format(commandList))
return
#!connect
if message.content.startswith('!connect'):
if ready:
await message.channel.send('Bot [{0}] is already connected to a voice channel.'.format(client.user))
return
channel = int(message.content[9:])
vc = await client.get_channel(channel).connect()
ready = True
await message.channel.send('Bot [{0}] is connecting to voice.'.format(client.user))
return
#!channels
if message.content.startswith('!channels'):
channelList = ''
for channel in client.get_all_channels():
if channel.type == discord.ChannelType.voice:
channelList += 'name: ' + channel.name + '\n'
channelList += 'id: ' + str(channel.id) + '\n\n'
await message.channel.send('{0}'.format(channelList))
return
#!add
if message.content.startswith('!add'):
song = message.content[5:]
if not path.exists(song):
await message.channel.send('Song not found or invalid path specified.\nSpecified Path: {0}\nExample command: !addSong C:\\Users\\Public\\Music\\mySong.mp3'.format(song))
return
songQueue.append(song)
await message.channel.send('Song added: {0}\nCurrent playist length: {1} song(s)'.format(song,len(songQueue)))
return
#!delete
if message.content.startswith('!delete'):
if len(songQueue) == 0:
await message.channel.send('Playlist is empty. Use !addSong, !viewList, and !playList to manage playlists.')
return
await message.channel.send('Removed song: {0}'.format(songQueue.pop()))
return
#!view
if message.content.startswith('!view'):
if len(songQueue) == 0:
await message.channel.send('Playlist is empty. Use !addSong, !deleteSong, and !playList to manage playlists.')
return
await message.channel.send('Current Playlist:\n{0}'.format('\n'.join(songQueue)))
return
#play commands
if message.content.startswith('!play'):
if not ready:
await message.channel.send('Bot [{0}] is not connected to a voice channel.'.format(client.user))
return
#!playlist
if message.content.startswith('!playlist'):
try:
songIndex = int(message.content[10:]) - 1
if songIndex >= len(songQueue):
songIndex = len(songQueue) - 1
except:
pass
playSong()
return
#!playSong
if message.content.startswith('!playSong'):
song = message.content[10:]
if not path.exists(song):
await message.channel.send('Song not found or invalid path specified.\nSpecified Path: {0}\nExample command: !play C:\\Users\\Public\\Music\\mySong.mp3'.format(song))
return
source = discord.FFmpegPCMAudio(song)
vc.play(source, after=None)
await message.channel.send('Playing song: {0}'.format(song))
return
#!next
if message.content.startswith('!next'):
vc.stop()
#!prev
if message.content.startswith('!prev'):
songIndex -= 2
if songIndex < -1:
songIndex = -1
vc.stop()
#!stop
if message.content.startswith('!stop'):
if not ready:
await message.channel.send('Bot [{0}] is not connected to a voice channel.'.format(client.user))
return
vc.stop()
songIndex = 0
stopPlaylist = True
await message.channel.send('Stopping music.')
return
#!pause
if message.content.startswith('!pause'):
if not ready:
await message.channel.send('Bot [{0}] is not connected to a voice channel.'.format(client.user))
return
vc.pause()
await message.channel.send('Pausing music.')
return
#!resume
if message.content.startswith('!resume'):
if not ready:
await message.channel.send('Bot [{0}] is not connected to a voice channel.'.format(client.user))
return
vc.resume()
await message.channel.send('Resuming music.')
return
#!status
if message.content.startswith('!status'):
if not ready:
await message.channel.send('Bot [{0}] is not connected to a voice channel.'.format(client.user))
return
if vc.is_playing():
await message.channel.send('Something is playing.')
return
await message.channel.send('Nothing is playing.')
return
def playSong():
global songQueue
global songIndex
global vc
try:
song = songQueue[songIndex]
source = discord.FFmpegPCMAudio(song)
vc.play(source, after=nextSong)
except Exception as e:
print('playSong error {0}'.format(e))
def nextSong(error):
global songQueue
global songIndex
global stopPlaylist
try:
songIndex += 1
if songIndex >= len(songQueue):
stopPlaylist = True
if stopPlaylist:
songIndex = 0
stopPlaylist = False
return
futureFunction = asyncio.run_coroutine_threadsafe(playSong(), client.loop)
futureFunction.result()
except Exception as e:
print('nextSong error {0}'.format(e))
#@client.event
#async def on_logout(user)
# global ready
# if user == client.user:
# ready = False
client.run('TOKEN')
最佳答案
好的,您必须知道的是,您可以访问您的本地驱动器,因为机器人在其上运行,但是您当然不能访问其他用户的驱动器(这将非常危险)。 discord.py 和 Discord 都不允许这样做。
关于python-3.x - Discord.py:访问发送者计算机上的文件。从服务器上任何用户的本地驱动器播放歌曲,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66959866/
我使用的是 Windows 8.1 和 Python 2.7,我在特定文件路径中设置了所有文件(希望正确),但每当我运行 python manage.py runserver 时,我都会收到此错误。
背景: 我有一个像这样的目录结构: Package/ setup.py src/ __init__.py __main__.py cod
我从这个线程运行了一个示例代码。 How to properly use coverage.py in Python? 但是,当我执行此命令时 py.test test.py --cov=sample
IPython 0.13.1 文档说: $ ipython -h ... Usage ipython [subcommand] [options] [files] If invoked
我写了一个网站,让我困惑的是当我运行这个网站时,首先我需要启动应用程序,所以有 3 种方法: sudo python xxx.py python xxx.py xxx.py 每一个我都不清楚怎么用,目
我不确定为什么它不起作用,这可能是一个您无法解决的问题,但我只是想知道为什么它不起作用。如果我浪费了您的时间,或者没有正确地提出问题,我很抱歉,我 16 岁,对 Python 还算陌生。 在main.
鉴于以下情况:models.py from .managers import PersonManager from django.db import models class Person(model
有没有办法将参数传递给 web.py 处理程序类构造函数? 例如。这些参数可能来自命令行(当主 web.py 脚本运行时),在第一个参数(作为端口号)之后 最佳答案 当然,这取决于你的意思。毕竟都是p
我对 python/django 编程很陌生,因为我没有编程背景。我正在在线上课,我只想确切地知道 manage.py 文件的作用。我试过用谷歌搜索它,但除了在 django-admin.py 周围放
我想将类别及其子类别保存到数据库中,这里每个类别都有多个子类别。您能帮我保存与类别相对应的用户、类别和多个子类别吗?Models.py、Serializers.py、Views .py 并附加传入请求
所以我的机器人开始有很多命令,并且在 main.py 上变得有点困惑。我知道有一种方法可以将命令存储在其他文件中,然后在 discord.js 上触发它们时将它们应用于 main.py。在 disco
我正在尝试制作一个类似于 mee6 的 Discord 机器人,因为它会按特定时间间隔计算用户在我的 Discord 服务器中发送的消息。我已经在网上搜索过,但即使有类似的问题也找不到我要找的东西。例
我正在尝试制作一个机器人,它根据特定 channel 中的消息创建线程。如果有在 discord.py 中的文本 channel 中创建线程的方法,请告诉我。 最佳答案 是的,但有一个问题。 当前版本
我一直在尝试制作一个命令来显示一些信息,然后当我对表情使用react时,它应该会显示另一组信息。 我尝试使用 this 的部分内容,特别是第 335 到 393 行的部分让它工作。但是,它什么也不做。
这是我试过的代码: @client.event async def on_message(message): if client.user.mention in message.content
我试过这段代码,机器人说猜但没有回应我的猜测。 @commands.command() async def game(self, ctx): number = random.randint(0
我决定尝试让我的不和谐机器人播放音乐,但我已经卡住了。主要是因为我找不到任何资源来帮助当前版本,我一直在从文档中获取所有内容。但是,我不知道如何检查机器人是否已连接到语音 channel 。 我试过
我在一个目录中有三个文件: # Untitled-1.py print("UTITLEDPY") if __name__== "__main__": from telegram.ext imp
我对 python 相当陌生,并且一直只使用 Jupyter Notebooks。当我需要运行我已保存在计算机中某处的 .py 文件时,我通常所做的就是使用魔术命令 %run %run '/home/
我有 Django 1.4 和 Python 2.6.6当我使用“django-amdin.py startproject djproject”时,请按照网页中的步骤操作 https://www.ib
我是一名优秀的程序员,十分优秀!